Skip to content

Commit

Permalink
Fixes not working livenet examples.
Browse files Browse the repository at this point in the history
Reenabled livenet tests.
  • Loading branch information
kubaplas committed Mar 4, 2024
1 parent 37789b7 commit 5044e98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ jobs:
test:
name: Test
runs-on: buildjet-8vcpu-ubuntu-2204
services:
casper-nctl:
image: makesoftware/casper-nctl:latest
options: --name mynctl
env:
PREDEFINED_ACCOUNTS: 'true'
MINIMUM_ROUND_EXPONENT: '12'
MAXIMUM_ROUND_EXPONENT: '14'
DEPLOY_DELAY: '12sec'
ports:
- 11101:11101
steps:
- name: Setup just
uses: extractions/setup-just@v1
Expand All @@ -39,3 +50,5 @@ jobs:
run: just prepare-test-env
- name: Run tests
run: just test
- name: Run livenet tests
run: just test-livenet
9 changes: 6 additions & 3 deletions examples/bin/erc20_on_livenet.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Deploys an ERC20 contract and transfers some tokens to another address.
use odra::casper_types::U256;
use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader};
use odra::Address;
Expand All @@ -21,18 +22,20 @@ fn main() {
println!("Token name: {}", token.name());

env.set_gas(3_000_000_000u64);
token.transfer(recipient, U256::from(1000));
token.transfer(&recipient, &U256::from(1000));

println!("Owner's balance: {:?}", token.balance_of(owner));
println!("Recipient's balance: {:?}", token.balance_of(recipient));
println!("Owner's balance: {:?}", token.balance_of(&owner));
println!("Recipient's balance: {:?}", token.balance_of(&recipient));
}

/// Loads an ERC20 contract.
fn _load_erc20(env: &HostEnv) -> Erc20HostRef {
let address = "hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945";
let address = Address::from_str(address).unwrap();
Erc20HostRef::load(env, address)
}

/// Deploys an ERC20 contract.
pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef {
let name = String::from("Plascoin");
let symbol = String::from("PLS");
Expand Down
8 changes: 5 additions & 3 deletions examples/bin/livenet_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! This example demonstrates how to deploy and interact with a contract on the Livenet environment.
use odra::casper_types::U256;
use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader};
use odra::Address;
Expand Down Expand Up @@ -43,9 +44,9 @@ fn main() {
assert_eq!(contract.immutable_cross_call(), 10_000.into());

// - mutable crosscalls will require a deploy
let pre_call_balance = erc20.balance_of(env.caller());
let pre_call_balance = erc20.balance_of(&env.caller());
contract.mutable_cross_call();
let post_call_balance = erc20.balance_of(env.caller());
let post_call_balance = erc20.balance_of(&env.caller());
assert_eq!(post_call_balance, pre_call_balance + 1);

// We can change the caller
Expand All @@ -62,7 +63,7 @@ fn deploy_new(env: &HostEnv) -> (LivenetContractHostRef, Erc20HostRef) {
erc20_address: *erc20_contract.address()
};
let livenet_contract = LivenetContractHostRef::deploy(env, init_args);
erc20_contract.transfer(*livenet_contract.address(), 1000.into());
erc20_contract.transfer(livenet_contract.address(), &1000.into());
(livenet_contract, erc20_contract)
}

Expand All @@ -77,6 +78,7 @@ fn load(
)
}

/// Deploys an ERC20 contract
pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef {
let name = String::from("Plascoin");
let symbol = String::from("PLS");
Expand Down

0 comments on commit 5044e98

Please sign in to comment.