Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Remove cross_staking mock from vault tests #115

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 129 additions & 41 deletions contracts/provider/vault/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,15 @@ fn stake_cross_txs() {
.call(owner)
.unwrap();

// Set active validator
let validator = "validator";

let activate = AddValidator::mock(validator);
cross_staking
.test_set_active_validator(activate)
.call("test")
.unwrap();

// Bond some tokens

vault
Expand Down Expand Up @@ -1003,7 +1012,10 @@ fn stake_cross_txs() {
.stake_remote(
cross_staking.contract_addr.to_string(),
coin(100, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
Expand All @@ -1018,7 +1030,10 @@ fn stake_cross_txs() {
.stake_remote(
cross_staking.contract_addr.to_string(),
coin(50, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
Expand All @@ -1030,7 +1045,10 @@ fn stake_cross_txs() {
.stake_remote(
cross_staking.contract_addr.to_string(),
coin(100, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user2)
.unwrap();
Expand Down Expand Up @@ -1078,7 +1096,7 @@ fn stake_cross_txs() {
.unwrap()
.claims,
[LienResponse {
lienholder: "contract0".to_string(),
lienholder: "contract2".to_string(),
amount: ValueRange::new(Uint128::zero(), Uint128::new(150))
}]
);
Expand Down Expand Up @@ -1218,6 +1236,15 @@ fn stake_cross_rollback_tx() {
.call(owner)
.unwrap();

// Set active validator
let validator = "validator";

let activate = AddValidator::mock(validator);
cross_staking
.test_set_active_validator(activate)
.call("test")
.unwrap();

// Bond some tokens

vault
Expand All @@ -1241,7 +1268,10 @@ fn stake_cross_rollback_tx() {
.stake_remote(
cross_staking.contract_addr.to_string(),
coin(100, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
Expand Down Expand Up @@ -1327,6 +1357,7 @@ fn multiple_stakes() {
.unwrap();

let unbond_period = 100;
let slashing_percentage: u64 = 60;
let remote_contact = AuthorizedEndpoint::new("connection-2", "wasm-osmo1foobarbaz");

let cross_staking1 = cross_staking_code
Expand All @@ -1336,7 +1367,7 @@ fn multiple_stakes() {
vault.contract_addr.to_string(),
unbond_period,
remote_contact.clone(),
Decimal::percent(SLASHING_PERCENTAGE),
Decimal::percent(slashing_percentage),
)
.call(owner)
.unwrap();
Expand All @@ -1348,14 +1379,28 @@ fn multiple_stakes() {
vault.contract_addr.to_string(),
unbond_period,
remote_contact,
Decimal::percent(SLASHING_PERCENTAGE),
Decimal::percent(slashing_percentage),
)
.call(owner)
.unwrap();

let local_staking = Addr::unchecked(vault.config().unwrap().local_staking);
let local_staking = local_staking::multitest_utils::LocalStakingProxy::new(local_staking, &app);

// Set active validator
let validator = "validator";

let activate = AddValidator::mock(validator);
cross_staking1
.test_set_active_validator(activate.clone())
.call("test")
.unwrap();

cross_staking2
.test_set_active_validator(activate)
.call("test")
.unwrap();

// Bond some tokens

vault
Expand All @@ -1379,28 +1424,44 @@ fn multiple_stakes() {
.stake_remote(
cross_staking1.contract_addr.to_string(),
coin(200, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(cross_staking1.contract_addr.as_str())

// TODO: Hardcoded external-staking's commit_stake call (lack of IBC support yet).
// This should be through `IbcPacketAckMsg`
let last_external_staking_tx =
get_last_external_staking_pending_tx_id(&cross_staking1).unwrap();
println!("last_external_staking_tx: {:?}", last_external_staking_tx);
cross_staking1
.test_commit_stake(last_external_staking_tx)
.call("test")
.unwrap();

vault
.stake_remote(
cross_staking2.contract_addr.to_string(),
coin(100, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(cross_staking2.contract_addr.as_str())

// TODO: Hardcoded external-staking's commit_stake call (lack of IBC support yet).
// This should be through `IbcPacketAckMsg`
let last_external_staking_tx =
get_last_external_staking_pending_tx_id(&cross_staking2).unwrap();
println!("last_external_staking_tx: {:?}", last_external_staking_tx);
cross_staking2
.test_commit_stake(last_external_staking_tx)
.call("test")
.unwrap();

assert_eq!(
Expand All @@ -1415,6 +1476,10 @@ fn multiple_stakes() {
assert_eq!(
claims.claims,
[
LienResponse {
lienholder: local_staking.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(300))
},
LienResponse {
lienholder: cross_staking1.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(200))
Expand All @@ -1423,10 +1488,6 @@ fn multiple_stakes() {
lienholder: cross_staking2.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(100))
},
LienResponse {
lienholder: local_staking.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(300))
},
]
);

Expand All @@ -1440,28 +1501,44 @@ fn multiple_stakes() {
.stake_remote(
cross_staking1.contract_addr.to_string(),
coin(200, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(cross_staking1.contract_addr.as_str())

// TODO: Hardcoded external-staking's commit_stake call (lack of IBC support yet).
// This should be through `IbcPacketAckMsg`
let last_external_staking_tx =
get_last_external_staking_pending_tx_id(&cross_staking1).unwrap();
println!("last_external_staking_tx: {:?}", last_external_staking_tx);
cross_staking1
.test_commit_stake(last_external_staking_tx)
.call("test")
.unwrap();

vault
.stake_remote(
cross_staking2.contract_addr.to_string(),
coin(400, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(cross_staking2.contract_addr.as_str())

// TODO: Hardcoded external-staking's commit_stake call (lack of IBC support yet).
// This should be through `IbcPacketAckMsg`
let last_external_staking_tx =
get_last_external_staking_pending_tx_id(&cross_staking2).unwrap();
println!("last_external_staking_tx: {:?}", last_external_staking_tx);
cross_staking2
.test_commit_stake(last_external_staking_tx)
.call("test")
.unwrap();

assert_eq!(
Expand All @@ -1476,6 +1553,10 @@ fn multiple_stakes() {
assert_eq!(
claims.claims,
[
LienResponse {
lienholder: local_staking.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(300))
},
LienResponse {
lienholder: cross_staking1.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(400))
Expand All @@ -1484,10 +1565,6 @@ fn multiple_stakes() {
lienholder: cross_staking2.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(500))
},
LienResponse {
lienholder: local_staking.contract_addr.to_string(),
amount: ValueRange::new_val(Uint128::new(300))
},
]
);

Expand All @@ -1499,21 +1576,32 @@ fn multiple_stakes() {
.stake_remote(
cross_staking1.contract_addr.to_string(),
coin(500, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(cross_staking1.contract_addr.as_str())

// TODO: Hardcoded external-staking's commit_stake call (lack of IBC support yet).
// This should be through `IbcPacketAckMsg`
let last_external_staking_tx =
get_last_external_staking_pending_tx_id(&cross_staking1).unwrap();
println!("last_external_staking_tx: {:?}", last_external_staking_tx);
cross_staking1
.test_commit_stake(last_external_staking_tx)
.call("test")
.unwrap();

let err = vault
.stake_remote(
cross_staking2.contract_addr.to_string(),
coin(400, OSMO),
Binary::default(),
to_binary(&ReceiveVirtualStake {
validator: validator.to_string(),
})
.unwrap(),
)
.call(user)
.unwrap_err();
Expand Down
Loading