diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 00000000..64b2e242 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,27 @@ +name: benchmark + +on: + push: + branches: + - 'release/**' + - 'feature/**' + paths-ignore: + - '**.md' + +jobs: + benchmark: + name: Benchmark + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: extractions/setup-just@v1 + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + target: wasm32-unknown-unknown + - run: just prepare-test-env + - run: just benchmark + - run: echo "BENCHMARK_FILENAME=${GITHUB_HEAD_REF}" | sed 's:/:-:g' >> $GITHUB_ENV + - uses: actions/upload-artifact@v4 + with: + name: ${{ env.BENCHMARK_FILENAME }} + path: benchmark/gas_report.json \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..17d05179 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,26 @@ +name: tests + +on: + pull_request: + branches: + - 'release/**' + paths-ignore: + - '**.md' + +jobs: + coverage: + name: Coverage + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: extractions/setup-just@v1 + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rustfmt, clippy, llvm-tools-preview + - run: just check-lint + - run: just prepare-test-env + - run: just coverage + - uses: codecov/codecov-action@v3 + with: + files: target/coverage/*.lcov diff --git a/.github/workflows/evaluate-benchmark.yml b/.github/workflows/evaluate-benchmark.yml new file mode 100644 index 00000000..9decd508 --- /dev/null +++ b/.github/workflows/evaluate-benchmark.yml @@ -0,0 +1,32 @@ +name: tests + +on: + pull_request: + branches: + - 'release/**' + - 'feature/**' + paths-ignore: + - '**.md' + +jobs: + evaluate_benchmark: + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: extractions/setup-just@v1 + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + target: wasm32-unknown-unknown + - run: just prepare-test-env + - run: echo "TARGET_BENCHMARK=${GITHUB_BASE_REF}" | sed 's:/:-:g' >> $GITHUB_ENV + - uses: actions/download-artifact@v4 + with: + name: ${{ env.TARGET_BENCHMARK }} + path: benchmark/target_gas_report.json + - run: just evaluate-benchmark + - name: Create comment + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: context.issue.number + body: | + Testing diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..70d561e5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: tests + +on: + pull_request: + branches: + - 'release/**' + - 'feature/**' + paths-ignore: + - '**.md' + +jobs: + test: + name: Test + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: extractions/setup-just@v1 + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rustfmt, clippy, llvm-tools-preview + - run: just check-lint + - run: just prepare-test-env + - run: just test \ No newline at end of file diff --git a/examples/bin/erc20_on_livenet.rs b/examples/bin/erc20_on_livenet.rs index 60fdeb6b..12861325 100644 --- a/examples/bin/erc20_on_livenet.rs +++ b/examples/bin/erc20_on_livenet.rs @@ -12,11 +12,11 @@ fn main() { let recipient = Address::from_str(recipient).unwrap(); // Deploy new contract. - let mut token = deploy_new(&env); + let mut token = deploy_erc20(&env); println!("Token address: {}", token.address().to_string()); // Uncomment to load existing contract. - // let mut token = load(&env); + // let mut token = load_erc20(&env); println!("Token name: {}", token.name()); @@ -27,7 +27,13 @@ fn main() { println!("Recipient's balance: {:?}", token.balance_of(recipient)); } -fn deploy_new(env: &HostEnv) -> Erc20HostRef { +fn _load_erc20(env: &HostEnv) -> Erc20HostRef { + let address = "hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945"; + let address = Address::from_str(address).unwrap(); + Erc20HostRef::load(env, address) +} + +pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef { let name = String::from("Plascoin"); let symbol = String::from("PLS"); let decimals = 10u8; @@ -43,9 +49,3 @@ fn deploy_new(env: &HostEnv) -> Erc20HostRef { env.set_gas(100_000_000_000u64); Erc20HostRef::deploy(env, init_args) } - -fn _load(env: &HostEnv) -> Erc20HostRef { - let address = "hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945"; - let address = Address::from_str(address).unwrap(); - Erc20HostRef::load(env, address) -} diff --git a/examples/bin/livenet_tests.rs b/examples/bin/livenet_tests.rs index b7eb215c..778204a1 100644 --- a/examples/bin/livenet_tests.rs +++ b/examples/bin/livenet_tests.rs @@ -1,9 +1,9 @@ +use odra::casper_types::U256; use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader}; use odra::Address; use odra_examples::features::livenet::{LivenetContractHostRef, LivenetContractInitArgs}; use odra_modules::access::events::OwnershipTransferred; -use odra_modules::erc20::Erc20HostRef; -use std::str::FromStr; +use odra_modules::erc20::{Erc20HostRef, Erc20InitArgs}; fn main() { let env = odra_casper_livenet_env::env(); @@ -11,18 +11,12 @@ fn main() { let owner = env.caller(); // Contract can be deployed - // env.set_gas(30_000_000_000u64); - // let contract = deploy_new(&env); - // println!("Contract address: {}", contract.address().to_string()); + env.set_gas(30_000_000_000u64); + let (contract, erc20) = deploy_new(&env); + println!("Contract address: {}", contract.address().to_string()); // Contract can be loaded - // let mut contract = load(&env, *contract.address()); - - // Uncomment to load existing contract - let address = - Address::from_str("hash-bd80e12b6d189e3b492932fc08e1342b540555c60e299ea3563d81ad700997e0") - .unwrap(); - let mut contract = load(&env, address); + let (mut contract, erc20) = load(&env, *contract.address(), *erc20.address()); // Set gas will be used for all subsequent calls env.set_gas(1_000_000_000u64); @@ -49,36 +43,53 @@ fn main() { assert_eq!(contract.immutable_cross_call(), 10_000.into()); // - mutable crosscalls will require a deploy - let erc20 = Erc20HostRef::load(&env, erc20_address()); let pre_call_balance = erc20.balance_of(env.caller()); contract.mutable_cross_call(); let post_call_balance = erc20.balance_of(env.caller()); assert_eq!(post_call_balance, pre_call_balance + 1); // We can change the caller - env.set_caller(env.get_account(2)); + env.set_caller(env.get_account(1)); // And query the balance println!("Balance of caller: {}", env.balance_of(&env.caller())); } -fn _deploy_new(env: &HostEnv) -> LivenetContractHostRef { +fn deploy_new(env: &HostEnv) -> (LivenetContractHostRef, Erc20HostRef) { + let mut erc20_contract = deploy_erc20(env); env.set_gas(100_000_000_000u64); let init_args = LivenetContractInitArgs { - erc20_address: erc20_address() + erc20_address: *erc20_contract.address() }; let livenet_contract = LivenetContractHostRef::deploy(env, init_args); - Erc20HostRef::load(env, erc20_address()).transfer(*livenet_contract.address(), 1000.into()); - livenet_contract + erc20_contract.transfer(*livenet_contract.address(), 1000.into()); + (livenet_contract, erc20_contract) } -fn erc20_address() -> Address { - // Following contract is deployed on integration livenet, change it to address from erc20_on_livenet example - Address::from_str("hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945") - .unwrap() +fn load( + env: &HostEnv, + contract_address: Address, + erc20_address: Address +) -> (LivenetContractHostRef, Erc20HostRef) { + ( + LivenetContractHostRef::load(env, contract_address), + Erc20HostRef::load(env, erc20_address) + ) } -fn load(env: &HostEnv, address: Address) -> LivenetContractHostRef { - Erc20HostRef::load(env, erc20_address()); - LivenetContractHostRef::load(env, address) +pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef { + let name = String::from("Plascoin"); + let symbol = String::from("PLS"); + let decimals = 10u8; + let initial_supply = Some(U256::from(10_000)); + + let init_args = Erc20InitArgs { + name, + symbol, + decimals, + initial_supply + }; + + env.set_gas(100_000_000_000u64); + Erc20HostRef::deploy(env, init_args) } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index c2dc9f7f..e78e997e 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] - extern crate alloc; pub mod contracts; diff --git a/justfile b/justfile index b62706c0..cb27a553 100644 --- a/justfile +++ b/justfile @@ -39,6 +39,9 @@ prepare-test-env: install-cargo-odra tar -xzf binaryen-{{BINARYEN_VERSION}}-x86_64-linux.tar.gz || { echo "Extraction failed"; exit 1; } sudo cp binaryen-{{BINARYEN_VERSION}}/bin/wasm-opt /usr/local/bin/wasm-opt +start-casper-node: + docker run --rm -it --name mynctl -d -p 11101:11101 -p 14101:14101 -p 18101:18101 makesoftware/casper-nctl + build-proxy-callers: cd odra-casper/proxy-caller && cargo build --release --target wasm32-unknown-unknown --target-dir ../../target wasm-strip target/wasm32-unknown-unknown/release/proxy_caller.wasm @@ -71,6 +74,17 @@ test-modules: test-modules-on-odravm test-modules-on-casper test: test-odra test-examples test-modules +test-livenet: + set shell := bash + mkdir -p examples/.node-keys + cp modules/wasm/Erc20.wasm examples/wasm/ + # Extract the secret keys from the local Casper node + docker exec mynctl /bin/bash -c "cat /home/casper/casper-node/utils/nctl/assets/net-1/users/user-1/secret_key.pem" > examples/.node-keys/secret_key.pem + docker exec mynctl /bin/bash -c "cat /home/casper/casper-node/utils/nctl/assets/net-1/users/user-2/secret_key.pem" > examples/.node-keys/secret_key_1.pem + # Run the tests + cd examples && ODRA_CASPER_LIVENET_SECRET_KEY_PATH=.node-keys/secret_key.pem ODRA_CASPER_LIVENET_NODE_ADDRESS=http://localhost:11101 ODRA_CASPER_LIVENET_CHAIN_NAME=casper-net-1 ODRA_CASPER_LIVENET_KEY_1=.node-keys/secret_key_1.pem cargo run --bin livenet_tests --features=livenet + rm -rf examples/.node-keys + run-example-erc20-on-livenet: cd examples && cargo run --bin erc20-on-livenet --features casper-livenet --no-default-features