Skip to content

Commit 694064e

Browse files
committed
Update scenario_3 abci test
Create a validator with more voting power than the genesis validator causing it to unbond.
1 parent 91447b0 commit 694064e

4 files changed

Lines changed: 92 additions & 6 deletions

File tree

gaia-rs/tests/abci/assets/scenario_3_genesis.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"pub_key": null,
1515
"account_number": "0",
1616
"sequence": "0"
17+
},
18+
{
19+
"@type": "/cosmos.auth.v1beta1.BaseAccount",
20+
"address": "cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q",
21+
"pub_key": null,
22+
"account_number": "0",
23+
"sequence": "0"
1724
}
1825
]
1926
},
@@ -31,6 +38,15 @@
3138
"amount": "1000000000000"
3239
}
3340
]
41+
},
42+
{
43+
"address": "cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q",
44+
"coins": [
45+
{
46+
"amount": "10000000000000",
47+
"denom": "uatom"
48+
}
49+
]
3450
}
3551
],
3652
"denom_metadata": []
@@ -147,4 +163,4 @@
147163
"redelegations": [],
148164
"exported": false
149165
}
150-
}
166+
}

gaia-rs/tests/abci/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ mod scenario_3;
2424
#[cfg(test)]
2525
mod two_tx;
2626

27+
// cosmos1syavy2npfyt9tcncdtsdzf7kny9lh777pahuux
2728
const USER_0: &str = "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow";
29+
// cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q
2830
const USER_1: &str = "unfair live spike near cushion blanket club salad poet cigar venue above north speak harbor salute curve tail appear obvious month end boss priority";
2931

3032
// This is a helper function to create a user with a specific account number

gaia-rs/tests/abci/scenario_3.rs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ fn scenario_3() {
2121
let genesis_path = Path::new("./tests/abci/assets/scenario_3_genesis.json");
2222
let (mut node, _) = setup_mock_node(Some(genesis_path));
2323
let user_0 = crate::user(2, USER_0);
24-
let user_1 = crate::user(5, USER_1);
24+
let user_1 = crate::user(3, USER_1);
2525

2626
let app_hash = node.step(vec![], Timestamp::UNIX_EPOCH);
2727
assert_eq!(
2828
hex::encode(app_hash),
29-
"de9ac6bd42e68571b724fe738e59d0ce1670e2e4720ad81be22cd75adcc30b54"
29+
"e111f4a62a52f13c7e942694aa9c6997f4f6e131b9306090aa022297ce362540"
3030
);
3131

3232
//----------------------------------------
33-
// Try to create the same validator as the one in the genesis file - should fail
33+
// Try to create a validator with the same pubkey as the one in the genesis file - should fail
3434

3535
let consensus_pub_key = serde_json::from_str::<PublicKey>(
3636
r#"{
@@ -67,7 +67,7 @@ fn scenario_3() {
6767
let app_hash = node.step(txs, Timestamp::try_new(0, 0).unwrap());
6868
assert_eq!(
6969
hex::encode(app_hash),
70-
"2b52579b7599ffac4bccef19e6cb2ab3b039ab3bc8c3ce072f12f60ec924132b"
70+
"6d0b1e5f3f4f3759c05be2eabed1f4586d176ab36f76df7d9b874dbe850016c8"
7171
);
7272

7373
// query the validator list
@@ -85,4 +85,71 @@ fn scenario_3() {
8585

8686
let res = QueryValidatorsResponse::decode(res.value).unwrap();
8787
assert_eq!(res.validators.len(), 1);
88+
89+
//----------------------------------------
90+
// Create a validator with more voting power than the one in the genesis file - should cause the genesis validator to be unbonded
91+
92+
let consensus_pub_key = serde_json::from_str::<PublicKey>(
93+
r#"{
94+
"type": "tendermint/PubKeyEd25519",
95+
"value": "NJWo4rSXCswNmK0Bttxzb8/1ioFNkRVi6Fio2KzAlCo="
96+
}"#,
97+
)
98+
.expect("hardcoded is valid");
99+
100+
let msg =
101+
gaia_rs::message::Message::Staking(staking::Message::CreateValidator(CreateValidator {
102+
description: Description {
103+
moniker: "test".to_string(),
104+
identity: "".to_string(),
105+
website: "".to_string(),
106+
details: "".to_string(),
107+
security_contact: "".to_string(),
108+
},
109+
commission: CommissionRates::new(
110+
"0.1".parse().expect("hardcoded is valid"),
111+
"1".parse().expect("hardcoded is valid"),
112+
"0.1".parse().expect("hardcoded is valid"),
113+
)
114+
.expect("hardcoded is valid"),
115+
min_self_delegation: Uint256::from(100u32),
116+
delegator_address: user_1.address(),
117+
validator_address: user_1.address().into(),
118+
pubkey: consensus_pub_key,
119+
value: "20000000000uatom".parse().expect("hardcoded is valid"),
120+
}));
121+
122+
let txs = generate_txs([(0, msg)], &user_1, node.chain_id().clone());
123+
124+
let app_hash = node.step(txs, Timestamp::try_new(0, 0).expect("hardcoded is valid"));
125+
assert_eq!(
126+
hex::encode(app_hash),
127+
"815b88380e50eb8a82f9df53503dddb14cba409970aaf77e7de1164ca8bc61f5"
128+
);
129+
130+
// query the validator list
131+
let query = QueryValidatorsRequest {
132+
status: BondStatus::Unbonding,
133+
pagination: None,
134+
};
135+
136+
let res = node.query(RequestQuery {
137+
data: query.encode_vec().into(),
138+
path: "/cosmos.staking.v1beta1.Query/Validators".to_string(),
139+
height: 0,
140+
prove: false,
141+
});
142+
143+
let res = QueryValidatorsResponse::decode(res.value).unwrap();
144+
assert_eq!(res.validators.len(), 1);
145+
assert_eq!(res.validators[0].operator_address, user_0.address().into());
146+
147+
//----------------------------------------
148+
// Jump forward in time - the unbonding validator will be unbonded
149+
150+
let app_hash = node.step(vec![], Timestamp::try_new(60 * 60 * 24 * 30, 0).unwrap()); // 30 days which is greater than the unbonding time
151+
assert_eq!(
152+
hex::encode(app_hash),
153+
"07f42dc05073c352627503e52acd89538ddcf08a0bb7d385027938f32013cc1e"
154+
);
88155
}

gears/src/baseapp/abci.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ impl<DB: Database, PSK: ParamsSubspaceKey, H: ABCIHandler, AI: ApplicationInfo>
278278
let consensus_params = self.baseapp_params_keeper.consensus_params(&ctx);
279279

280280
state.replace_meter(Gas::from(max_gas));
281-
state.take_block_cache(&mut multi_store);
282281

283282
let mut ctx = BlockContext::new(
284283
&mut multi_store,
@@ -302,6 +301,8 @@ impl<DB: Database, PSK: ParamsSubspaceKey, H: ABCIHandler, AI: ApplicationInfo>
302301
let mut state = self.state.write().expect(POISONED_LOCK);
303302
let mut multi_store = self.multi_store.write().expect(POISONED_LOCK);
304303

304+
state.take_block_cache(&mut multi_store);
305+
305306
let header = self.get_block_header();
306307

307308
let consensus_params = {

0 commit comments

Comments
 (0)