Skip to content

Commit c8ba735

Browse files
authored
feat: add a integration testing case (#51)
1 parent 32f0842 commit c8ba735

35 files changed

+945
-695
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
[dependencies]
88
anyhow = "1.0"
99
async-trait = "0.1"
10-
axon-types = { git = "https://github.com/axonweb3/axon-contract", rev = "33e1736" }
10+
axon-types = { git = "https://github.com/axonweb3/axon-contract", rev = "991eaa0" }
1111
bytes = "1.0"
1212
chrono = "0.4"
1313
ckb-fixed-hash-core = "0.109"

common/src/traits/tx_builder.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ pub trait IInitTxBuilder<'a, C: CkbRpc> {
1717
seeder_key: PrivateKey,
1818
max_supply: Amount,
1919
checkpoint: Checkpoint,
20-
epoch0_metadata: Metadata,
21-
epoch1_metadata: Metadata,
20+
metadata: MetadataInfo,
2221
stakers: Vec<StakerEthAddr>,
2322
) -> Self;
2423

@@ -78,16 +77,16 @@ where
7877
C: CkbRpc,
7978
S: RewardSmtStorage + StakeSmtStorage + DelegateSmtStorage + ProposalSmtStorage,
8079
{
81-
fn new(
80+
async fn new(
8281
ckb: &'a C,
8382
type_ids: RewardTypeIds,
8483
smt: S,
85-
info: RewardInfo,
8684
user: EthAddress,
8785
current_epoch: Epoch,
86+
epoch_count: u64,
8887
) -> Self;
8988

90-
async fn build_tx(self) -> Result<TransactionView>;
89+
async fn build_tx(mut self) -> Result<TransactionView>;
9190
}
9291

9392
#[async_trait]
@@ -128,7 +127,6 @@ pub trait IStakeSmtTxBuilder<'a, C: CkbRpc, S: StakeSmtStorage> {
128127
kicker: PrivateKey,
129128
current_epoch: Epoch,
130129
type_ids: StakeSmtTypeIds,
131-
quorum: u16,
132130
stake_cells: Vec<Cell>,
133131
stake_smt_storage: S,
134132
) -> Self;

common/src/types/tx_builder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,16 @@ impl From<Metadata> for AMetadata {
522522
}
523523
}
524524

525-
pub struct RewardInfo {
525+
#[derive(Clone, Default)]
526+
pub struct RewardMeta {
526527
pub base_reward: Amount,
527528
pub half_reward_cycle: Epoch,
528-
pub minimum_propose_count: u64,
529+
pub propose_minimum_rate: u8,
529530
pub propose_discount_rate: u8,
530-
pub epoch_count: u64,
531+
}
532+
533+
pub struct MetadataInfo {
534+
pub reward_meta: RewardMeta,
535+
pub epoch0_metadata: Metadata,
536+
pub epoch1_metadata: Metadata,
531537
}

devtools/tx-tests/README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,42 @@ delegator_privkeys = [
2828
```
2929

3030
# Run
31+
32+
## Run cases
33+
34+
```
35+
cd spark/devtools/tx-tests
36+
37+
cargo run -- cases -n test -1
38+
```
39+
40+
## Run single tx
3141
```
3242
cd spark/devtools/tx-tests
3343
34-
cargo run -- -f // faucet (only used on the dev chain)
44+
cargo run -- single-tx -n test -f // faucet (only used on the dev chain)
3545
36-
cargo run -- -i // init tx
46+
cargo run -- single-tx -n test -i // init tx
3747
38-
cargo run -- -m // mint tx
48+
cargo run -- single-tx -n test -m // mint tx
3949
4050
// stake tx
41-
cargo run -- -s first // first stake
42-
cargo run -- -s add // add stake
43-
cargo run -- -s redeem // redeem stake
51+
cargo run -- single-tx -n test -s first // first stake
52+
cargo run -- single-tx -n test -s add // add stake
53+
cargo run -- single-tx -n test -s redeem // redeem stake
4454
4555
// delegate tx
46-
cargo run -- -s first // first delegate
47-
cargo run -- -s add // add delegate
48-
cargo run -- -s redeem // redeem delegate
56+
cargo run -- single-tx -n test -s first // first delegate
57+
cargo run -- single-tx -n test -s add // add delegate
58+
cargo run -- single-tx -n test -s redeem // redeem delegate
4959
50-
cargo run -- -t // stake smt tx
60+
cargo run -- single-tx -n test -t // stake smt tx
5161
52-
cargo run -- -e // delegate smt tx
62+
cargo run -- single-tx -n test -e // delegate smt tx
5363
54-
cargo run -- -w // withdraw tx
64+
cargo run -- single-tx -n test -w // withdraw tx
5565
56-
cargo run -- -a // metadata tx
66+
cargo run -- single-tx -n test -a // metadata tx
5767
58-
cargo run -- -r // reward tx
68+
cargo run -- single-tx -n test -r // reward tx
5969
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::fs;
2+
use std::path::Path;
3+
4+
use rpc_client::ckb_client::ckb_rpc_client::CkbRpcClient;
5+
use tx_builder::ckb::helper::OmniEth;
6+
7+
use crate::config::types::PrivKeys;
8+
use crate::tx::*;
9+
use crate::ROCKSDB_PATH;
10+
11+
// There is only one staker or delegator.
12+
pub async fn run_case1(ckb: &CkbRpcClient, priv_keys: PrivKeys) {
13+
if Path::new(ROCKSDB_PATH).exists() {
14+
fs::remove_dir_all(ROCKSDB_PATH).unwrap();
15+
}
16+
17+
let kicker_key = priv_keys.staker_privkeys[0].clone().into_h256().unwrap();
18+
let staker_key = priv_keys.staker_privkeys[0].clone().into_h256().unwrap();
19+
let delegator_key = priv_keys.delegator_privkeys[0].clone().into_h256().unwrap();
20+
let staker_eth_addr = OmniEth::new(staker_key.clone()).address().unwrap();
21+
22+
run_init_tx(ckb, priv_keys.clone()).await;
23+
run_mint_tx(ckb, priv_keys.clone()).await;
24+
25+
first_stake_tx(ckb, staker_key.clone()).await;
26+
add_stake_tx(ckb, staker_key.clone()).await;
27+
run_stake_smt_tx(ckb, kicker_key.clone()).await;
28+
29+
reedem_stake_tx(ckb, staker_key.clone()).await;
30+
run_stake_smt_tx(ckb, kicker_key.clone()).await;
31+
32+
first_delegate_tx(ckb, delegator_key.clone(), staker_eth_addr.clone()).await;
33+
add_delegate_tx(ckb, delegator_key.clone(), staker_eth_addr.clone()).await;
34+
run_delegate_smt_tx(ckb, kicker_key.clone()).await;
35+
36+
reedem_delegate_tx(ckb, delegator_key, staker_eth_addr).await;
37+
run_delegate_smt_tx(ckb, kicker_key.clone()).await;
38+
39+
run_metadata_tx(ckb, kicker_key.clone()).await;
40+
41+
run_checkpoint_tx(ckb, priv_keys.clone(), 1).await;
42+
run_checkpoint_tx(ckb, priv_keys.clone(), 2).await;
43+
44+
run_reward_tx(ckb, staker_key.clone()).await;
45+
46+
run_withdraw_tx(ckb, staker_key.clone()).await;
47+
}

devtools/tx-tests/src/cases/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod case1;
2+
3+
pub use case1::run_case1;

devtools/tx-tests/src/config/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ use std::fs;
44
use std::io::Write;
55
use std::path::Path;
66

7-
use serde::{de, ser};
7+
use serde::ser;
88

9-
use common::config_parser::parse_file as cparse_file;
9+
use common::config_parser::{parse_file, types::ConfigLogger};
1010

11-
pub fn parse_file<T: de::DeserializeOwned>(path: impl AsRef<Path>) -> T {
12-
cparse_file(path, false).unwrap()
11+
use crate::config::types::{PrivKeys, TypeIds};
12+
13+
pub fn parse_priv_keys(path: impl AsRef<Path>) -> PrivKeys {
14+
let priv_keys: PrivKeys = parse_file(path, false).expect("priv keys");
15+
priv_keys
16+
}
17+
18+
pub fn parse_type_ids(path: impl AsRef<Path>) -> TypeIds {
19+
let type_ids: TypeIds = parse_file(path, false).expect("type ids");
20+
type_ids
21+
}
22+
23+
pub fn parse_log_config(path: impl AsRef<Path>) -> ConfigLogger {
24+
let config: ConfigLogger = parse_file(path, false).expect("log config");
25+
config
1326
}
1427

1528
pub fn write_file<T: ser::Serialize>(path: impl AsRef<Path>, content: &T) {
@@ -27,11 +40,11 @@ pub fn write_file<T: ser::Serialize>(path: impl AsRef<Path>, content: &T) {
2740
#[cfg(test)]
2841
mod tests {
2942
use super::types::*;
30-
use super::{parse_file, write_file};
43+
use super::{parse_priv_keys, parse_type_ids, write_file};
3144

3245
fn _test_parse_config() {
3346
let file_path = "./src/config/priv_keys.toml";
34-
let priv_keys: PrivKeys = parse_file(file_path);
47+
let priv_keys: PrivKeys = parse_priv_keys(file_path);
3548
println!("{:?}", priv_keys);
3649
}
3750

@@ -66,7 +79,7 @@ mod tests {
6679
};
6780
write_file(file_path, &type_ids);
6881

69-
let type_ids: TypeIds = parse_file(file_path);
82+
let type_ids: TypeIds = parse_type_ids(file_path);
7083
println!("{:?}", type_ids);
7184
}
7285
}

0 commit comments

Comments
 (0)