Skip to content

Commit

Permalink
add transfer->hook transfer->accept/burn tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abright committed Sep 20, 2022
1 parent 4d13eae commit 6ec08a3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions testing/fil_token_integration/tests/frc46_multi_actor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,46 @@ fn frc46_multi_actor_tests() {
let balance = tester.get_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));

// TEST: alice transfers to bob, bob transfers to carol (from hook), carol accepts
let params = action_params(
token_actor,
TestAction::Transfer(bob, action(TestAction::Transfer(carol, action(TestAction::Accept)))),
);
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
assert!(ret_val.msg_receipt.exit_code.is_success());
// check balances - alice should be empty, bob should keep 200, carol sitting on 100
let balance = tester.get_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.get_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.get_balance(operator[0].1, token_actor, carol);
assert_eq!(balance, TokenAmount::from_atto(100));

// TEST: alice transfers to bob, bob transfers to carol (from hook), carol burns (from hook)
// mint a bit to alice first
let ret_val = tester.mint_tokens(
operator[0].1,
token_actor,
alice,
TokenAmount::from_atto(100),
action(TestAction::Accept),
);
assert!(ret_val.msg_receipt.exit_code.is_success());
// now transfer alice->bob->carol and have carol burn the incoming balance
let params = action_params(
token_actor,
TestAction::Transfer(bob, action(TestAction::Transfer(carol, action(TestAction::Burn)))),
);
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
assert!(ret_val.msg_receipt.exit_code.is_success());
// check the receipt we got in return data
let receipt = ret_val.msg_receipt.return_data.deserialize::<Receipt>().unwrap();
assert!(receipt.exit_code.is_success());
// check balances - alice should be empty, bob should keep 200, carol sitting on 100
let balance = tester.get_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.get_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.get_balance(operator[0].1, token_actor, carol);
assert_eq!(balance, TokenAmount::from_atto(100));
}

0 comments on commit 6ec08a3

Please sign in to comment.