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

More integration tests #103

Merged
merged 32 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aa4eaf5
Add configurable test actor
abright Sep 8, 2022
23293ac
WIP configurable actor tests
abright Sep 9, 2022
0424763
Add operator_data to MintParams in the basic token actor
abright Sep 12, 2022
4c550fb
Don't blindly flush state after minting
abright Sep 12, 2022
13bd598
test: receiver hook burns incoming tokens after mint
abright Sep 12, 2022
e3f5639
MintParams formatting
abright Sep 12, 2022
a5a4988
wip make minting aware of changed state after receiver hook returns
abright Sep 12, 2022
3071ff1
wip better state reloading mechanism
abright Sep 13, 2022
e2557f6
more common stuff
abright Sep 19, 2022
0813771
single-actor tests
abright Sep 19, 2022
a8cec0b
keep TestAction and ActionParams as part of test_actor
abright Sep 19, 2022
fc5a45a
duplicate MintParams in common to avoid linking in the token actor ev…
abright Sep 19, 2022
9f530df
wip multi-actor tests
abright Sep 20, 2022
21cacac
don't explode the test actor if transfer within receiver hook fails
abright Sep 20, 2022
7c48437
add test to mint tokens and then transfer inside the receiver hook
abright Sep 20, 2022
30c0dfb
update Transfer and TransferFrom to have the same post-hook state han…
abright Sep 20, 2022
e81c3ad
return Transfer call result in test actor
abright Sep 20, 2022
c494ff9
add transfer->hook transfer->accept/burn tests
abright Sep 20, 2022
ea6793c
update transfer_tokens test to use the common helpers
abright Sep 20, 2022
3fbc19b
improve Token::replace and make public
abright Sep 21, 2022
cc49735
abort with an error instead of ignoring calls to Accept or Reject in …
abright Sep 21, 2022
37df1eb
rename get_balance to token_balance to avoid confusion with native to…
abright Sep 21, 2022
2acef81
separate individual frc46 tests into blocks
abright Sep 21, 2022
517abcf
add call_method_ok and mint_tokens_ok helpers to assert success and r…
abright Sep 21, 2022
d503d76
add token balance assertion helpers to further compress test case code
abright Sep 21, 2022
f9286e5
add more balance asserts and check the more complex transfer results
abright Sep 21, 2022
00e6c98
remove unnecessary comment
abright Sep 21, 2022
ad9ac07
return intermediate data through hook call and construct MintReturn a…
abright Sep 21, 2022
1755a96
return intermediate data through hook call and construct TransferFrom…
abright Sep 21, 2022
15afad7
return intermediate data through hook call and construct TransferRetu…
abright Sep 21, 2022
6d6fdb9
move transfer and burn actions in the test actor into separate functions
abright Sep 22, 2022
61355fd
bump frc46_token version to 0.2.0
abright Sep 22, 2022
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ members = [
"testing/fil_token_integration/actors/basic_receiving_actor",
"testing/fil_token_integration/actors/basic_nft_actor",
"testing/fil_token_integration/actors/basic_transfer_actor",
"testing/fil_token_integration/actors/test_actor"
]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test-coverage: install-toolchain
--exclude basic_token_actor \
--exclude basic_receiving_actor \
--exclude basic_nft_actor \
--exclude basic_transfer_actor
--exclude basic_transfer_actor \
--exclude test_actor

# separate actor testing stage to run from CI without coverage support
test-actors: install-toolchain
Expand Down
2 changes: 1 addition & 1 deletion frc46_token/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "frc46_token"
description = "Filecoin FRC-0046 fungible token reference implementation"
version = "0.1.0"
version = "0.2.0"
license = "MIT OR Apache-2.0"
keywords = ["filecoin", "fvm", "token", "frc-0046"]
repository = "https://github.com/helix-onchain/filecoin/"
Expand Down
169 changes: 111 additions & 58 deletions frc46_token/src/token/mod.rs

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions frc46_token/src/token/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,17 @@ pub struct MintReturn {
}

impl Cbor for MintReturn {}
impl RecipientData for MintReturn {

/// Intermediate data used by mint_return to construct the return data
#[derive(Debug)]
pub struct MintIntermediate {
/// Recipient address to use for querying balance
pub recipient: Address,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we restrict visibility of these to the crate? I'm undecided, so ok to leave public for now.

/// (Optional) data returned from receiver hook
pub recipient_data: RawBytes,
}

impl RecipientData for MintIntermediate {
fn set_recipient_data(&mut self, data: RawBytes) {
self.recipient_data = data;
}
Expand Down Expand Up @@ -158,7 +168,17 @@ pub struct TransferReturn {

impl Cbor for TransferParams {}
impl Cbor for TransferReturn {}
impl RecipientData for TransferReturn {

/// Intermediate data used by transfer_return to construct the return data
#[derive(Debug)]
pub struct TransferIntermediate {
pub from: Address,
pub to: Address,
/// (Optional) data returned from receiver hook
pub recipient_data: RawBytes,
}

impl RecipientData for TransferIntermediate {
fn set_recipient_data(&mut self, data: RawBytes) {
self.recipient_data = data;
}
Expand Down Expand Up @@ -190,7 +210,18 @@ pub struct TransferFromReturn {

impl Cbor for TransferFromParams {}
impl Cbor for TransferFromReturn {}
impl RecipientData for TransferFromReturn {

/// Intermediate data used by transfer_from_return to construct the return data
#[derive(Debug)]
pub struct TransferFromIntermediate {
pub operator: Address,
pub from: Address,
pub to: Address,
/// (Optional) data returned from receiver hook
pub recipient_data: RawBytes,
}

impl RecipientData for TransferFromIntermediate {
fn set_recipient_data(&mut self, data: RawBytes) {
self.recipient_data = data;
}
Expand Down
3 changes: 2 additions & 1 deletion testing/fil_token_integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cid = { version = "0.8.5", default-features = false }
fvm = { version = "2.0.0-alpha.2", default-features = false }
frcxx_nft = { path = "../../frcxx_nft" }
frc42_dispatch = { path = "../../frc42_dispatch" }
frc46_token = { version = "0.1.0", path = "../../frc46_token" }
frc46_token = { version = "0.2.0", path = "../../frc46_token" }
fvm_integration_tests = "2.0.0-alpha.1"
fvm_ipld_blockstore = "0.1.1"
fvm_ipld_encoding = "0.2.2"
Expand All @@ -24,3 +24,4 @@ basic_nft_actor = {path = "actors/basic_nft_actor"}
basic_receiving_actor = { path = "actors/basic_receiving_actor" }
basic_token_actor = { path = "actors/basic_token_actor" }
basic_transfer_actor = { path = "actors/basic_transfer_actor" }
test_actor = { path = "actors/test_actor" }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
frc46_token = { version = "0.1.0", path = "../../../../frc46_token" }
frc46_token = { version = "0.2.0", path = "../../../../frc46_token" }
frc42_dispatch = { path = "../../../../frc42_dispatch" }
fvm_ipld_blockstore = "0.1.1"
fvm_ipld_encoding = "0.2.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ repository = "https://github.com/helix-collective/filecoin"
edition = "2021"

[dependencies]
cid = { version = "0.8.5", default-features = false }
fvm_actor_utils = { version = "0.1.0", path = "../../../../fvm_actor_utils" }
fvm_ipld_blockstore = { version = "0.1.1" }
fvm_ipld_encoding = { version = "0.2.2" }
fvm_sdk = { version = "2.0.0-alpha.2" }
fvm_shared = { version = "2.0.0-alpha.2" }
frc46_token = { version = "0.1.0", path = "../../../../frc46_token" }
frc46_token = { version = "0.2.0", path = "../../../../frc46_token" }
num-traits = { version = "0.2.15" }
serde = { version = "1.0.136", features = ["derive"] }
serde_tuple = { version = "0.5.0" }
Expand Down
37 changes: 25 additions & 12 deletions testing/fil_token_integration/actors/basic_token_actor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod util;

use cid::Cid;
use frc46_token::token::types::{
AllowanceReturn, BalanceReturn, BurnFromReturn, BurnParams, BurnReturn,
DecreaseAllowanceParams, FRC46Token, GetAllowanceParams, GranularityReturn,
Expand Down Expand Up @@ -63,7 +64,10 @@ impl FRC46Token<RuntimeError> for BasicToken<'_> {
let cid = self.util.flush()?;
sdk::sself::set_root(&cid).unwrap();

let ret = hook.call(self.util.msg())?;
let hook_ret = hook.call(self.util.msg())?;

self.reload(&cid)?;
let ret = self.util.transfer_return(hook_ret)?;

Ok(ret)
}
Expand All @@ -85,7 +89,10 @@ impl FRC46Token<RuntimeError> for BasicToken<'_> {
let cid = self.util.flush()?;
sdk::sself::set_root(&cid).unwrap();

let ret = hook.call(self.util.msg())?;
let hook_ret = hook.call(self.util.msg())?;

self.reload(&cid)?;
let ret = self.util.transfer_from_return(hook_ret)?;

Ok(ret)
}
Expand Down Expand Up @@ -141,24 +148,37 @@ impl FRC46Token<RuntimeError> for BasicToken<'_> {
pub struct MintParams {
pub initial_owner: Address,
pub amount: TokenAmount,
pub operator_data: RawBytes,
}

impl Cbor for MintParams {}

impl BasicToken<'_> {
fn reload(&mut self, initial_cid: &Cid) -> Result<(), RuntimeError> {
// todo: revise error type here so it plays nice with the result and doesn't need unwrap
let new_cid = sdk::sself::root().unwrap();
if new_cid != *initial_cid {
self.util.load_replace(&new_cid)?;
}
Ok(())
}

fn mint(&mut self, params: MintParams) -> Result<MintReturn, RuntimeError> {
let mut hook = self.util.mint(
&caller_address(),
&params.initial_owner,
&params.amount,
Default::default(),
params.operator_data,
Default::default(),
)?;

let cid = self.util.flush()?;
sdk::sself::set_root(&cid).unwrap();

let ret = hook.call(self.util.msg())?;
let hook_ret = hook.call(self.util.msg())?;

self.reload(&cid)?;
let ret = self.util.mint_return(hook_ret)?;

Ok(ret)
}
Expand Down Expand Up @@ -269,28 +289,21 @@ pub fn invoke(params: u32) -> u32 {
// TransferFrom
let params = deserialize_params(params);
let res = token_actor.transfer_from(params).unwrap();
let cid = token_actor.util.flush().unwrap();
sdk::sself::set_root(&cid).unwrap();
return_ipld(&res).unwrap()
}
1303003700 => {
// Transfer
let params = deserialize_params(params);
let res = token_actor.transfer(params).unwrap();
let cid = token_actor.util.flush().unwrap();
sdk::sself::set_root(&cid).unwrap();
return_ipld(&res).unwrap()
}

// Custom actor interface, these are author-defined methods that extend beyond the
// FRC46 Token standard
3839021839 => {
// Mint
let params = deserialize_params(params);
let params: MintParams = deserialize_params(params);
let res = token_actor.mint(params).unwrap();

let cid = token_actor.util.flush().unwrap();
sdk::sself::set_root(&cid).unwrap();
return_ipld(&res).unwrap()
}
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
cid = { version = "0.8.5", default-features = false }
frc46_token = { version = "0.1.0", path = "../../../../frc46_token" }
frc46_token = { version = "0.2.0", path = "../../../../frc46_token" }
frc42_dispatch = { path = "../../../../frc42_dispatch" }
fvm_ipld_blockstore = { version = "0.1.1" }
fvm_ipld_encoding = { version = "0.2.2" }
Expand Down
18 changes: 18 additions & 0 deletions testing/fil_token_integration/actors/test_actor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "test_actor"
version = "0.1.0"
edition = "2021"

[dependencies]
cid = { version = "0.8.5", default-features = false }
frc46_token = { version = "0.2.0", path = "../../../../frc46_token" }
frc42_dispatch = { path = "../../../../frc42_dispatch" }
fvm_ipld_blockstore = { version = "0.1.1" }
fvm_ipld_encoding = { version = "0.2.2" }
fvm_sdk = { version = "2.0.0-alpha.2" }
fvm_shared = { version = "2.0.0-alpha.2" }
serde = { version = "1.0", features = ["derive"] }
serde_tuple = { version = "0.5.0" }

[build-dependencies]
wasm-builder = "3.0"
12 changes: 12 additions & 0 deletions testing/fil_token_integration/actors/test_actor/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main() {
use wasm_builder::WasmBuilder;
WasmBuilder::new()
.with_current_project()
.import_memory()
.append_to_rust_flags("-Ctarget-feature=+crt-static")
.append_to_rust_flags("-Cpanic=abort")
.append_to_rust_flags("-Coverflow-checks=true")
.append_to_rust_flags("-Clto=true")
.append_to_rust_flags("-Copt-level=z")
.build()
}
Loading