Search code examples
nearprotocol

NearProtocol simulation test example not compiling


TLDR: NEAR's FungibleToken example is the goto standard for how to write simulation tests, and it isn't compiling.

https://github.com/thor314/FungibleToken details my odyssey of trying to get the Fungible Token example to compile, so I can model my Simulation Tests off of it. The ReadMe contains what I've tried so far.

The original repo lives inside the near_sdk repo. https://github.com/near/near-sdk-rs/tree/master/examples/fungible-token


After @sirwillem's useful answer, this post is updated to reflect a residing error in the sim test:

---- test_sim_transfer stdout ----
thread 'test_sim_transfer' panicked at 'Outcome ExecutionOutcome {
    logs: [],
    receipt_ids: [
        `9S5QHJgLThMCPtgJbtARenx6duSLBu3oCCtVbVpEwdLC`,
    ],
    burnt_gas: 16326564288269,
    tokens_burnt: 0,
    status: Failure(Action #0: The account contract wouldn't have enough balance to cover storage, required to have 116059483300000000000000000 yoctoNEAR more),
} was a failure', /home/thor/.cargo/git/checkouts/near-sdk-rs-7ba52202f378a9d9/ea112e2/near-sdk-sim/src/outcome.rs:87:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Update 2; needed to update the .wasm file with the build script. Thanks.


Solution

  • Thank you for trudging into uncharted territory! We are still working to publish core crates in nearcore that the simulator depends on. Once we have this, we can publish it. This will stabilize it and you won't get these types of errors.

    For now to fix what you have edit your Cargo.toml to the newest tag for both:

    [dependencies]
    near-sdk = { git = "https://github.com/near/near-sdk-rs.git", tag="2.2.0" }
    
    
    [dev-dependencies]
    near-sdk-sim = { git = "https://github.com/near/near-sdk-rs.git", tag="2.2.0" }
    

    Then you have to edit general.rs on line 70 to:

            contract.transfer(alice.account_id(), transfer_amount.into()),