-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1231 from multiversx/foundry
Foundry-like tests
- Loading branch information
Showing
83 changed files
with
4,560 additions
and
419 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
*/target/ | ||
|
||
# The mxpy output | ||
/output*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "addercaller" | ||
version = "0.0.0" | ||
authors = [ "you",] | ||
edition = "2018" | ||
publish = false | ||
|
||
[lib] | ||
path = "src/addercaller.rs" | ||
|
||
[dev-dependencies] | ||
num-bigint = "0.4.2" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "0.41.1" | ||
|
||
[dev-dependencies.multiversx-sc-scenario] | ||
version = "0.41.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "addercaller-meta" | ||
version = "0.0.0" | ||
edition = "2018" | ||
publish = false | ||
authors = [ "you",] | ||
|
||
[dev-dependencies] | ||
|
||
[dependencies.addercaller] | ||
path = ".." | ||
|
||
[dependencies.multiversx-sc-meta] | ||
version = "0.41.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
multiversx_sc_meta::cli_main::<addercaller::AbiProvider>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"language": "rust" | ||
} |
178 changes: 178 additions & 0 deletions
178
contracts/foundry/addercaller/scenarios/addercaller.scen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
{ | ||
"name": "addercaller", | ||
"comment": "add then check", | ||
"gasSchedule": "v3", | ||
"steps": [ | ||
{ | ||
"step": "setState", | ||
"accounts": { | ||
"address:owner": { | ||
"nonce": "1", | ||
"balance": "100000", | ||
"esdt": { | ||
"str:MYESDT": "200" | ||
} | ||
} | ||
}, | ||
"newAddresses": [ | ||
{ | ||
"creatorAddress": "address:owner", | ||
"creatorNonce": "1", | ||
"newAddress": "sc:adder" | ||
}, | ||
{ | ||
"creatorAddress": "address:owner", | ||
"creatorNonce": "2", | ||
"newAddress": "sc:addercaller" | ||
} | ||
] | ||
}, | ||
{ | ||
"step": "scDeploy", | ||
"id": "deploy adder", | ||
"tx": { | ||
"from": "address:owner", | ||
"contractCode": "file:../../myadder/output/adder.wasm", | ||
"arguments": [ | ||
"5" | ||
], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scDeploy", | ||
"id": "deploy addercaller", | ||
"tx": { | ||
"from": "address:owner", | ||
"contractCode": "file:../output/addercaller.wasm", | ||
"arguments": [ | ||
"sc:adder" | ||
], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "call adder", | ||
"tx": { | ||
"from": "address:owner", | ||
"to": "sc:adder", | ||
"function": "add", | ||
"value": "1000", | ||
"arguments": [ | ||
"3" | ||
], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": ["8"], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "call addercaller egld", | ||
"tx": { | ||
"from": "address:owner", | ||
"to": "sc:addercaller", | ||
"function": "call_adder", | ||
"value": "1000", | ||
"arguments": [ | ||
"4" | ||
], | ||
"gasLimit": "15,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": ["12", "str:added"], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "call addercaller esdt", | ||
"tx": { | ||
"from": "address:owner", | ||
"to": "sc:addercaller", | ||
"function": "call_adder_esdt", | ||
"esdtValue": [ | ||
{ | ||
"tokenIdentifier": "str:MYESDT", | ||
"value": "30" | ||
} | ||
], | ||
"arguments": [ | ||
"5" | ||
], | ||
"gasLimit": "15,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": ["17", "str:added-esdt"], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "checkState", | ||
"accounts": { | ||
"address:owner": { | ||
"nonce": "*", | ||
"balance": "98000", | ||
"storage": {}, | ||
"code": "", | ||
"esdt": { | ||
"str:MYESDT": "170" | ||
} | ||
}, | ||
"sc:adder": { | ||
"nonce": "0", | ||
"balance": "1030", | ||
"storage": { | ||
"str:sum": "17" | ||
}, | ||
"code": "file:../../myadder/output/adder.wasm", | ||
"esdt": { | ||
"str:MYESDT": "20" | ||
} | ||
}, | ||
"sc:addercaller": { | ||
"nonce": "0", | ||
"balance": "970", | ||
"storage": { | ||
"str:dest": "sc:adder" | ||
}, | ||
"code": "file:../output/addercaller.wasm", | ||
"esdt": { | ||
"str:MYESDT": "10" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
69 changes: 69 additions & 0 deletions
69
contracts/foundry/addercaller/scenarios/addercaller_out_of_funds.scen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "addercaller", | ||
"comment": "add then check", | ||
"gasSchedule": "v3", | ||
"steps": [ | ||
{ | ||
"step": "setState", | ||
"accounts": { | ||
"address:owner": { | ||
"nonce": "1", | ||
"balance": "100000", | ||
"esdt": { | ||
"str:MYESDT": "200" | ||
} | ||
} | ||
}, | ||
"newAddresses": [ | ||
{ | ||
"creatorAddress": "address:owner", | ||
"creatorNonce": "1", | ||
"newAddress": "sc:adder" | ||
} | ||
] | ||
}, | ||
{ | ||
"step": "scDeploy", | ||
"id": "deploy adder", | ||
"tx": { | ||
"from": "address:owner", | ||
"contractCode": "file:../../myadder/output/adder.wasm", | ||
"arguments": [ | ||
"5" | ||
], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "call adder: insufficient EGLD balance", | ||
"tx": { | ||
"from": "address:owner", | ||
"to": "sc:adder", | ||
"function": "add", | ||
"value": "1000000", | ||
"arguments": [ | ||
"3" | ||
], | ||
"gasLimit": "5,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "7", | ||
"message": "*", | ||
"logs": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// A smart contract to test transfer & execute functions | ||
// Initialize the contract with the address of the adder | ||
// The endpoints `call_adder` and `call_adder_esdt` accepts | ||
// tokens in EGLD and ESDT and performs transfer & execute | ||
// to the adder's `add` endpoint. | ||
|
||
#![no_std] | ||
|
||
multiversx_sc::imports!(); | ||
|
||
/// One of the simplest smart contracts possible, | ||
/// it holds a single variable in storage, which anyone can increment. | ||
#[multiversx_sc::contract] | ||
pub trait AdderCaller { | ||
#[storage_mapper("dest")] | ||
fn dest(&self) -> SingleValueMapper<ManagedAddress>; | ||
|
||
#[init] | ||
fn init(&self, dest: &ManagedAddress) { | ||
self.dest().set(dest); | ||
} | ||
|
||
#[endpoint] | ||
#[payable("EGLD")] | ||
fn call_adder(&self, value: BigUint) -> ManagedBuffer { | ||
let mut arg_buffer = ManagedArgBuffer::new(); | ||
arg_buffer.push_arg(value); | ||
|
||
let result = self.send_raw().direct_egld_execute( | ||
&self.dest().get(), | ||
&BigUint::from(30u32), | ||
5000000, | ||
&ManagedBuffer::from(b"add"), | ||
&arg_buffer, | ||
); | ||
|
||
match result { | ||
Result::Err(e) => sc_panic!(e), | ||
Result::Ok(_) => ManagedBuffer::from("added"), | ||
} | ||
} | ||
|
||
#[endpoint] | ||
#[payable("MYESDT")] | ||
fn call_adder_esdt(&self, value: BigUint) -> ManagedBuffer { | ||
let mut arg_buffer = ManagedArgBuffer::new(); | ||
arg_buffer.push_arg(value); | ||
|
||
let result = self.send_raw().transfer_esdt_execute( | ||
&self.dest().get(), | ||
&TokenIdentifier::from_esdt_bytes(b"MYESDT"), | ||
&BigUint::from(20u32), | ||
5000000, | ||
&ManagedBuffer::from(b"add"), | ||
&arg_buffer, | ||
); | ||
|
||
match result { | ||
Result::Err(e) => sc_panic!(e), | ||
Result::Ok(_) => ManagedBuffer::from("added-esdt"), | ||
} | ||
} | ||
} | ||
|
||
// |
Oops, something went wrong.