Skip to content

Commit

Permalink
separate individual frc46 tests into blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
abright committed Sep 21, 2022
1 parent 37df1eb commit cc59756
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 202 deletions.
241 changes: 127 additions & 114 deletions testing/fil_token_integration/tests/frc46_multi_actor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,128 +44,141 @@ fn frc46_multi_actor_tests() {
}

// TEST: alice sends bob a transfer of zero amount (rejecting first time and then accepting)
// first, tell bob to reject it
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Reject)));
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
// we told bob to reject, so the action call should return success but give us the error result as return data
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());

// this time tell bob to accept it
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Accept)));
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
// we told bob to accept this time, so transfer should succeed
assert!(ret_val.msg_receipt.exit_code.is_success());

// balance should remain zero
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(0));
{
// first, tell bob to reject it
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Reject)));
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
// we told bob to reject, so the action call should return success but give us the error result as return data
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());
}
{
// this time tell bob to accept it
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Accept)));
let ret_val = tester.call_method(operator[0].1, alice, method_hash!("Action"), Some(params));
// we told bob to accept this time, so transfer should succeed
assert!(ret_val.msg_receipt.exit_code.is_success());

// balance should remain zero
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(0));
}
// TEST: alice sends bob a transfer of a non-zero amounnt. As before, we'll reject it the first time then accept
// mint some tokens 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());
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(100));
// now send to bob, who will reject them
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Reject)));
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());

// transfer to bob who will accept it this time
let params = action_params(token_actor, TestAction::Transfer(bob, 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
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(100));
{
// mint some tokens 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());
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(100));
// now send to bob, who will reject them
let params = action_params(token_actor, TestAction::Transfer(bob, action(TestAction::Reject)));
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());
}
{
// transfer to bob who will accept it this time
let params = action_params(token_actor, TestAction::Transfer(bob, 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
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(100));
}

// TEST: mint to alice who transfers to bob inside receiver hook, bob accepts
let ret_val = tester.mint_tokens(
operator[0].1,
token_actor,
alice,
TokenAmount::from_atto(100),
action(TestAction::Transfer(bob, action(TestAction::Accept))),
);
assert!(ret_val.msg_receipt.exit_code.is_success());
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
{
let ret_val = tester.mint_tokens(
operator[0].1,
token_actor,
alice,
TokenAmount::from_atto(100),
action(TestAction::Transfer(bob, action(TestAction::Accept))),
);
assert!(ret_val.msg_receipt.exit_code.is_success());
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
}

// TEST: mint to alice who transfers to bob inside receiver hook, bob rejects
let ret_val = tester.mint_tokens(
operator[0].1,
token_actor,
alice,
TokenAmount::from_atto(100),
action(TestAction::Transfer(bob, action(TestAction::Reject))),
);
// mint succeeds but the transfer inside the receiver hook would have failed
assert!(ret_val.msg_receipt.exit_code.is_success());
// alice should keep tokens in this case
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(100));
// bob's balance should remain unchanged
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
{
let ret_val = tester.mint_tokens(
operator[0].1,
token_actor,
alice,
TokenAmount::from_atto(100),
action(TestAction::Transfer(bob, action(TestAction::Reject))),
);
// mint succeeds but the transfer inside the receiver hook would have failed
assert!(ret_val.msg_receipt.exit_code.is_success());
// alice should keep tokens in this case
let balance = tester.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(100));
// bob's balance should remain unchanged
let balance = tester.token_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.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.token_balance(operator[0].1, token_actor, carol);
assert_eq!(balance, TokenAmount::from_atto(100));
{
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.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.token_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.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.token_balance(operator[0].1, token_actor, carol);
assert_eq!(balance, TokenAmount::from_atto(100));
{
// 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.token_balance(operator[0].1, token_actor, alice);
assert_eq!(balance, TokenAmount::from_atto(0));
let balance = tester.token_balance(operator[0].1, token_actor, bob);
assert_eq!(balance, TokenAmount::from_atto(200));
let balance = tester.token_balance(operator[0].1, token_actor, carol);
assert_eq!(balance, TokenAmount::from_atto(100));
}
}
Loading

0 comments on commit cc59756

Please sign in to comment.