Skip to content

Commit

Permalink
Merge branch 'release/0.9.0' into feature/benchmarking-gas-costs
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaplas committed Feb 12, 2024
2 parents 250cc51 + 05e110e commit 5b93140
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 35 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions .github/workflows/evaluate-benchmark.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions examples/bin/erc20_on_livenet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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;
Expand All @@ -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)
}
61 changes: 36 additions & 25 deletions examples/bin/livenet_tests.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
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();

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);
Expand All @@ -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)
}
1 change: 0 additions & 1 deletion examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]

extern crate alloc;

pub mod contracts;
Expand Down
14 changes: 14 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5b93140

Please sign in to comment.