Skip to content

Commit

Permalink
Update scenario_3 abci test
Browse files Browse the repository at this point in the history
Create a validator with more voting power than the genesis validator
causing it to unbond.
  • Loading branch information
joneskm committed Sep 26, 2024
1 parent 91447b0 commit 694064e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
18 changes: 17 additions & 1 deletion gaia-rs/tests/abci/assets/scenario_3_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"pub_key": null,
"account_number": "0",
"sequence": "0"
},
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"address": "cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q",
"pub_key": null,
"account_number": "0",
"sequence": "0"
}
]
},
Expand All @@ -31,6 +38,15 @@
"amount": "1000000000000"
}
]
},
{
"address": "cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q",
"coins": [
{
"amount": "10000000000000",
"denom": "uatom"
}
]
}
],
"denom_metadata": []
Expand Down Expand Up @@ -147,4 +163,4 @@
"redelegations": [],
"exported": false
}
}
}
2 changes: 2 additions & 0 deletions gaia-rs/tests/abci/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ mod scenario_3;
#[cfg(test)]
mod two_tx;

// cosmos1syavy2npfyt9tcncdtsdzf7kny9lh777pahuux
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";
// cosmos15qzm75pjh0jqsv3u40hzp2vzs2hdp47fkz7j5q
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";

// This is a helper function to create a user with a specific account number
Expand Down
75 changes: 71 additions & 4 deletions gaia-rs/tests/abci/scenario_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ fn scenario_3() {
let genesis_path = Path::new("./tests/abci/assets/scenario_3_genesis.json");
let (mut node, _) = setup_mock_node(Some(genesis_path));
let user_0 = crate::user(2, USER_0);
let user_1 = crate::user(5, USER_1);
let user_1 = crate::user(3, USER_1);

let app_hash = node.step(vec![], Timestamp::UNIX_EPOCH);
assert_eq!(
hex::encode(app_hash),
"de9ac6bd42e68571b724fe738e59d0ce1670e2e4720ad81be22cd75adcc30b54"
"e111f4a62a52f13c7e942694aa9c6997f4f6e131b9306090aa022297ce362540"
);

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

let consensus_pub_key = serde_json::from_str::<PublicKey>(
r#"{
Expand Down Expand Up @@ -67,7 +67,7 @@ fn scenario_3() {
let app_hash = node.step(txs, Timestamp::try_new(0, 0).unwrap());
assert_eq!(
hex::encode(app_hash),
"2b52579b7599ffac4bccef19e6cb2ab3b039ab3bc8c3ce072f12f60ec924132b"
"6d0b1e5f3f4f3759c05be2eabed1f4586d176ab36f76df7d9b874dbe850016c8"
);

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

let res = QueryValidatorsResponse::decode(res.value).unwrap();
assert_eq!(res.validators.len(), 1);

//----------------------------------------
// Create a validator with more voting power than the one in the genesis file - should cause the genesis validator to be unbonded

let consensus_pub_key = serde_json::from_str::<PublicKey>(
r#"{
"type": "tendermint/PubKeyEd25519",
"value": "NJWo4rSXCswNmK0Bttxzb8/1ioFNkRVi6Fio2KzAlCo="
}"#,
)
.expect("hardcoded is valid");

let msg =
gaia_rs::message::Message::Staking(staking::Message::CreateValidator(CreateValidator {
description: Description {
moniker: "test".to_string(),
identity: "".to_string(),
website: "".to_string(),
details: "".to_string(),
security_contact: "".to_string(),
},
commission: CommissionRates::new(
"0.1".parse().expect("hardcoded is valid"),
"1".parse().expect("hardcoded is valid"),
"0.1".parse().expect("hardcoded is valid"),
)
.expect("hardcoded is valid"),
min_self_delegation: Uint256::from(100u32),
delegator_address: user_1.address(),
validator_address: user_1.address().into(),
pubkey: consensus_pub_key,
value: "20000000000uatom".parse().expect("hardcoded is valid"),
}));

let txs = generate_txs([(0, msg)], &user_1, node.chain_id().clone());

let app_hash = node.step(txs, Timestamp::try_new(0, 0).expect("hardcoded is valid"));
assert_eq!(
hex::encode(app_hash),
"815b88380e50eb8a82f9df53503dddb14cba409970aaf77e7de1164ca8bc61f5"
);

// query the validator list
let query = QueryValidatorsRequest {
status: BondStatus::Unbonding,
pagination: None,
};

let res = node.query(RequestQuery {
data: query.encode_vec().into(),
path: "/cosmos.staking.v1beta1.Query/Validators".to_string(),
height: 0,
prove: false,
});

let res = QueryValidatorsResponse::decode(res.value).unwrap();
assert_eq!(res.validators.len(), 1);
assert_eq!(res.validators[0].operator_address, user_0.address().into());

//----------------------------------------
// Jump forward in time - the unbonding validator will be unbonded

let app_hash = node.step(vec![], Timestamp::try_new(60 * 60 * 24 * 30, 0).unwrap()); // 30 days which is greater than the unbonding time
assert_eq!(
hex::encode(app_hash),
"07f42dc05073c352627503e52acd89538ddcf08a0bb7d385027938f32013cc1e"
);
}
3 changes: 2 additions & 1 deletion gears/src/baseapp/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ impl<DB: Database, PSK: ParamsSubspaceKey, H: ABCIHandler, AI: ApplicationInfo>
let consensus_params = self.baseapp_params_keeper.consensus_params(&ctx);

state.replace_meter(Gas::from(max_gas));
state.take_block_cache(&mut multi_store);

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

state.take_block_cache(&mut multi_store);

let header = self.get_block_header();

let consensus_params = {
Expand Down

0 comments on commit 694064e

Please sign in to comment.