Giter VIP home page Giter VIP logo

fuel_low_level_contract_calling_testing's Introduction

Low Level Contract Call testing

There are two contracts:

├── contracts
│   ├── caller
│   └── target

We want to call the target contract via caller, using call_with_function_selector in Sway, and .call_low_level_call() in the Rust SDK.

Compile the contracts using:

./0_build_contracts.sh

Im using forc 0.42.1 and as indicated in fuel-toolchain.toml.

the CallerContract uses a method straight out of the fuels-rs repo.

The low level caller contract "CallerContract" is the same as: https://github.com/FuelLabs/fuels-rs/blob/master/packages/fuels/tests/contracts/low_level_caller/src/main.sw

The TargetContract has a few simple methods: set() and get() to set storage variables and a get method to check if the values were stored correctly.

I have annotated the ./tests/harness.rs file with the methods that work and ones that dont.

To test:

Start local fuel-core:

Using fuel-core version 0.19.1

fuel-core run --ip 127.0.0.1 --port 4000 --db-type in-memory

Using the build in wallet:

pub const WALLET_FROM_FUEL_CORE: &str =
    "de97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c";

Deploy contracts:

from inside project root directory.

./1_deploy_contracts.sh

OR using cargo:

cargo test --package llcall_testing --test integration_tests -- deploy_contracts --exact --show-output

Test Methods individually:

test_set0_get0 using low level call - This one works:

cargo test --package llcall_testing --test integration_tests -- test_set0_get0 --exact --show-output

test_set1_get1 using low level call - This Fails:

cargo test --package llcall_testing --test integration_tests -- test_set1_get1 --exact --show-output

test_set2_get2 using low level call - This Fails:

cargo test --package llcall_testing --test integration_tests -- test_set2_get2 --exact --show-output

test_set3_get3 using low level call - This Fails: attempts to populate a struct as call data:

DemoStruct {
    a: true,
    b: [1, 2, 3],
    c: 22u64,
}
cargo test --package llcall_testing --test integration_tests -- test_set3_get3 --exact --show-output

Check Sanity:

Call set3 directly with a populated DemoStruct and read back - This works.

cargo test --package llcall_testing --test integration_tests -- direct_call_set3_get3 --exact --show-output

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.