Skip to content

Commit

Permalink
delete release_all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemka374 committed Sep 19, 2023
1 parent 8b72efe commit efee515
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 85 deletions.
63 changes: 5 additions & 58 deletions examples/payment_splitter/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ pub mod my_payment_splitter {
#[rustfmt::skip]
use ink_e2e::{build_message, PolkadotConfig};

use test_helpers::{address_of, get_shares, method_call};
use test_helpers::{
address_of,
get_shares,
method_call,
};

type E2EResult<T> = Result<T, Box<dyn std::error::Error>>;

Expand Down Expand Up @@ -154,62 +158,5 @@ pub mod my_payment_splitter {

Ok(())
}

#[ink_e2e::test]
async fn release_native_token_using_release_all(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
let constructor = ContractRef::new(vec![(address_of!(Bob), 40), (address_of!(Alice), 60)]);
let address = client
.instantiate("my_payment_splitter", &ink_e2e::alice(), constructor, 0, None)
.await
.expect("instantiate failed")
.account_id;

let total_released_before = method_call!(client, address, total_released);

assert_eq!(total_released_before, 0);

let _receive_tx = {
let _msg = build_message::<ContractRef>(address.clone()).call(|contract| contract.receive());
client
.call(&ink_e2e::alice(), _msg, 1000000000000, None)
.await
.expect("call failed")
.return_value()
};

let release_all = method_call!(client, address, release_all);

assert!(release_all.is_ok());

let total_released = method_call!(client, address, total_released);

let bob_released = {
let _msg =
build_message::<ContractRef>(address.clone()).call(|contract| contract.released(address_of!(Bob)));
client
.call_dry_run(&ink_e2e::alice(), &_msg, 0, None)
.await
.return_value()
};

let alice_released = {
let _msg = build_message::<ContractRef>(address.clone())
.call(|contract| contract.released(address_of!(Alice)));
client
.call_dry_run(&ink_e2e::alice(), &_msg, 0, None)
.await
.return_value()
};

assert!(alice_released > bob_released);

assert_eq!(bob_released, (total_released * 40) / 100);

assert_eq!(alice_released, (total_released * 60) / 100);

assert_eq!(alice_released + bob_released, total_released);

Ok(())
}
}
}
27 changes: 0 additions & 27 deletions tests/payment_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,33 +242,6 @@ mod payment_splitter {
);
}

#[ink::test]
fn correct_release_all() {
let accounts = accounts();
let mut instance = MySplitter::new(vec![(accounts.charlie, 100), (accounts.bob, 200)]);
ink::env::test::set_account_balance::<ink::env::DefaultEnvironment>(accounts.charlie, 0);
ink::env::test::set_account_balance::<ink::env::DefaultEnvironment>(accounts.bob, 0);
let amount = 1000000;
add_funds(instance.env().account_id(), amount);

assert_eq!(100 + 200, PaymentSplitter::total_shares(&mut instance,));
assert_eq!(999999, PaymentSplitter::total_released(&mut instance,));
assert_eq!(333333, PaymentSplitter::released(&mut instance, accounts.charlie));
assert_eq!(
333333,
ink::env::test::get_account_balance::<ink::env::DefaultEnvironment>(accounts.charlie).unwrap()
);
assert_eq!(2 * 333333, PaymentSplitter::released(&mut instance, accounts.bob));
assert_eq!(
2 * 333333,
ink::env::test::get_account_balance::<ink::env::DefaultEnvironment>(accounts.bob).unwrap()
);

let emitted_events = ink::env::test::recorded_events().collect::<Vec<_>>();
assert_payment_released_event(&emitted_events[2], accounts.charlie, 333333);
assert_payment_released_event(&emitted_events[3], accounts.bob, 2 * 333333);
}

fn add_funds(account: AccountId, amount: Balance) {
let balance = ink::env::balance::<ink::env::DefaultEnvironment>();
ink::env::test::set_account_balance::<ink::env::DefaultEnvironment>(account, balance + amount);
Expand Down

0 comments on commit efee515

Please sign in to comment.