Skip to content

Commit

Permalink
Add more tests for staking extrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
doom committed Jun 3, 2024
1 parent 136962d commit 33ff36c
Showing 1 changed file with 169 additions and 0 deletions.
169 changes: 169 additions & 0 deletions rust/chains/tw_polkadot/tests/extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use tw_polkadot::extrinsic::Extrinsic;
use tw_proto::Polkadot::Proto;
use tw_proto::Polkadot::Proto::mod_Balance::{AssetTransfer, BatchAssetTransfer, Transfer};
use tw_proto::Polkadot::Proto::mod_Identity::mod_AddAuthorization::{AuthData, Data};
use tw_proto::Polkadot::Proto::mod_Staking::{
Bond, BondExtra, Chill, Nominate, Rebond, Unbond, WithdrawUnbonded,
};

#[test]
fn polymesh_encode_transfer_with_memo() {
Expand Down Expand Up @@ -318,3 +321,169 @@ fn kusama_encode_asset_transfer_without_call_indices() {
let extrinsic = Extrinsic::from_input(input);
extrinsic.encode_call().expect_err("unexpected success");
}

#[test]
fn encode_staking_nominate() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::nominate(Nominate {
nominators: vec![
"13wQDQTMM6E9g5WD27e6UsWWTwHLaW763FQxnkbVaoKmsBQy".into(),
"14ixj163bkk2UEKLEXsEWosuFNuijpqEWZbX5JzN4yMHbUVD".into(),
],
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(
encoded.to_hex(),
"0705080081f5dd1432e5dd60aa71819e1141ad5e54d6f4277d7d128030154114444b8c9100a4b558a0342ae6e379a7ed00d23ff505f1101646cb279844496ad608943eda0d",
);
}

#[test]
fn encode_staking_chill() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::chill(Chill {
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "0706");
}

#[test]
fn encode_staking_bond_with_controller() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::bond(Bond {
controller: "13wQDQTMM6E9g5WD27e6UsWWTwHLaW763FQxnkbVaoKmsBQy".into(),
value: U256::from(808081u64).to_little_endian().to_vec().into(),
reward_destination: Proto::RewardDestination::CONTROLLER,
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(
encoded.to_hex(),
"07000081f5dd1432e5dd60aa71819e1141ad5e54d6f4277d7d128030154114444b8c914652310002"
);
}

#[test]
fn encode_staking_bond() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::bond(Bond {
controller: Default::default(),
value: U256::from(808081u64).to_little_endian().to_vec().into(),
reward_destination: Proto::RewardDestination::STAKED,
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "07004652310000");
}

#[test]
fn encode_staking_bond_extra() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::bond_extra(BondExtra {
value: U256::from(808081u64).to_little_endian().to_vec().into(),
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "070146523100");
}

#[test]
fn encode_staking_rebond() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::rebond(Rebond {
value: U256::from(808081u64).to_little_endian().to_vec().into(),
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "071346523100");
}

#[test]
fn encode_staking_unbond() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::unbond(Unbond {
value: U256::from(808081u64).to_little_endian().to_vec().into(),
call_indices: None,
}),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "070246523100");
}

#[test]
fn encode_staking_withdraw_unbonded() {
let input = Proto::SigningInput {
network: 0,
multi_address: true,
message_oneof: Proto::mod_SigningInput::OneOfmessage_oneof::staking_call(Proto::Staking {
message_oneof: Proto::mod_Staking::OneOfmessage_oneof::withdraw_unbonded(
WithdrawUnbonded {
slashing_spans: 84,
call_indices: None,
},
),
}),
..Default::default()
};

let extrinsic = Extrinsic::from_input(input);
let encoded = extrinsic.encode_call().expect("error encoding call");
assert_eq!(encoded.to_hex(), "070354000000");
}

0 comments on commit 33ff36c

Please sign in to comment.