-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix testutils invoke with incorrect arg count
- Loading branch information
1 parent
91fe9c9
commit 6885e92
Showing
6 changed files
with
1,091 additions
and
0 deletions.
There are no files selected for viewing
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
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,73 @@ | ||
use crate as soroban_sdk; | ||
use soroban_sdk::{contract, contractimpl, symbol_short, vec, Address, Env, IntoVal as _}; | ||
|
||
#[contract] | ||
pub struct Contract; | ||
|
||
#[contractimpl] | ||
impl Contract { | ||
pub fn add_with(env: Env, x: i32, y: Option<i32>, z: Option<i32>, contract_id: Address) -> i32 { | ||
let mut args = vec![&env, x.into_val(&env)]; | ||
if let Some(y) = y { | ||
args.push_back(y.into_val(&env)); | ||
} | ||
if let Some(z) = z { | ||
args.push_back(z.into_val(&env)); | ||
} | ||
env.invoke_contract(&contract_id, &symbol_short!("add"), args) | ||
} | ||
} | ||
|
||
#[contract] | ||
pub struct AddContract; | ||
|
||
#[contractimpl] | ||
impl AddContract { | ||
pub fn add(_: Env, a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_correct_arg_count() { | ||
let e = Env::default(); | ||
|
||
let add_contract_id = e.register_contract(None, AddContract); | ||
|
||
let contract_id = e.register_contract(None, Contract); | ||
let client = ContractClient::new(&e, &contract_id); | ||
|
||
let x = 10i32; | ||
let y = 12i32; | ||
let z = client.add_with(&x, &Some(y), &None, &add_contract_id); | ||
assert!(z == 22); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "invalid number of input arguments: 2 expected, got 1")] | ||
fn test_too_few_args() { | ||
let e = Env::default(); | ||
|
||
let add_contract_id = e.register_contract(None, AddContract); | ||
|
||
let contract_id = e.register_contract(None, Contract); | ||
let client = ContractClient::new(&e, &contract_id); | ||
|
||
let x = 10i32; | ||
let _ = client.add_with(&x, &None, &None, &add_contract_id); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "invalid number of input arguments: 2 expected, got 3")] | ||
fn test_too_many_args() { | ||
let e = Env::default(); | ||
|
||
let add_contract_id = e.register_contract(None, AddContract); | ||
|
||
let contract_id = e.register_contract(None, Contract); | ||
let client = ContractClient::new(&e, &contract_id); | ||
|
||
let x = 10i32; | ||
let y = 12i32; | ||
let _ = client.add_with(&x, &Some(y), &Some(1), &add_contract_id); | ||
} |
224 changes: 224 additions & 0 deletions
224
soroban-sdk/test_snapshots/tests/contract_invoke_arg_count/test_correct_arg_count.1.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,224 @@ | ||
{ | ||
"generators": { | ||
"address": 2, | ||
"nonce": 0 | ||
}, | ||
"auth": [ | ||
[] | ||
], | ||
"ledger": { | ||
"protocol_version": 21, | ||
"sequence_number": 0, | ||
"timestamp": 0, | ||
"network_id": "0000000000000000000000000000000000000000000000000000000000000000", | ||
"base_reserve": 0, | ||
"min_persistent_entry_ttl": 4096, | ||
"min_temp_entry_ttl": 16, | ||
"max_entry_ttl": 6312000, | ||
"ledger_entries": [ | ||
[ | ||
{ | ||
"contract_data": { | ||
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", | ||
"key": "ledger_key_contract_instance", | ||
"durability": "persistent" | ||
} | ||
}, | ||
[ | ||
{ | ||
"last_modified_ledger_seq": 0, | ||
"data": { | ||
"contract_data": { | ||
"ext": "v0", | ||
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", | ||
"key": "ledger_key_contract_instance", | ||
"durability": "persistent", | ||
"val": { | ||
"contract_instance": { | ||
"executable": { | ||
"wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" | ||
}, | ||
"storage": null | ||
} | ||
} | ||
} | ||
}, | ||
"ext": "v0" | ||
}, | ||
4095 | ||
] | ||
], | ||
[ | ||
{ | ||
"contract_data": { | ||
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4", | ||
"key": "ledger_key_contract_instance", | ||
"durability": "persistent" | ||
} | ||
}, | ||
[ | ||
{ | ||
"last_modified_ledger_seq": 0, | ||
"data": { | ||
"contract_data": { | ||
"ext": "v0", | ||
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4", | ||
"key": "ledger_key_contract_instance", | ||
"durability": "persistent", | ||
"val": { | ||
"contract_instance": { | ||
"executable": { | ||
"wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" | ||
}, | ||
"storage": null | ||
} | ||
} | ||
} | ||
}, | ||
"ext": "v0" | ||
}, | ||
4095 | ||
] | ||
], | ||
[ | ||
{ | ||
"contract_code": { | ||
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" | ||
} | ||
}, | ||
[ | ||
{ | ||
"last_modified_ledger_seq": 0, | ||
"data": { | ||
"contract_code": { | ||
"ext": "v0", | ||
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"code": "" | ||
} | ||
}, | ||
"ext": "v0" | ||
}, | ||
4095 | ||
] | ||
] | ||
] | ||
}, | ||
"events": [ | ||
{ | ||
"event": { | ||
"ext": "v0", | ||
"contract_id": null, | ||
"type_": "diagnostic", | ||
"body": { | ||
"v0": { | ||
"topics": [ | ||
{ | ||
"symbol": "fn_call" | ||
}, | ||
{ | ||
"bytes": "0000000000000000000000000000000000000000000000000000000000000002" | ||
}, | ||
{ | ||
"symbol": "add_with" | ||
} | ||
], | ||
"data": { | ||
"vec": [ | ||
{ | ||
"i32": 10 | ||
}, | ||
{ | ||
"i32": 12 | ||
}, | ||
"void", | ||
{ | ||
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"failed_call": false | ||
}, | ||
{ | ||
"event": { | ||
"ext": "v0", | ||
"contract_id": "0000000000000000000000000000000000000000000000000000000000000002", | ||
"type_": "diagnostic", | ||
"body": { | ||
"v0": { | ||
"topics": [ | ||
{ | ||
"symbol": "fn_call" | ||
}, | ||
{ | ||
"bytes": "0000000000000000000000000000000000000000000000000000000000000001" | ||
}, | ||
{ | ||
"symbol": "add" | ||
} | ||
], | ||
"data": { | ||
"vec": [ | ||
{ | ||
"i32": 10 | ||
}, | ||
{ | ||
"i32": 12 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"failed_call": false | ||
}, | ||
{ | ||
"event": { | ||
"ext": "v0", | ||
"contract_id": "0000000000000000000000000000000000000000000000000000000000000001", | ||
"type_": "diagnostic", | ||
"body": { | ||
"v0": { | ||
"topics": [ | ||
{ | ||
"symbol": "fn_return" | ||
}, | ||
{ | ||
"symbol": "add" | ||
} | ||
], | ||
"data": { | ||
"i32": 22 | ||
} | ||
} | ||
} | ||
}, | ||
"failed_call": false | ||
}, | ||
{ | ||
"event": { | ||
"ext": "v0", | ||
"contract_id": "0000000000000000000000000000000000000000000000000000000000000002", | ||
"type_": "diagnostic", | ||
"body": { | ||
"v0": { | ||
"topics": [ | ||
{ | ||
"symbol": "fn_return" | ||
}, | ||
{ | ||
"symbol": "add_with" | ||
} | ||
], | ||
"data": { | ||
"i32": 22 | ||
} | ||
} | ||
} | ||
}, | ||
"failed_call": false | ||
} | ||
] | ||
} |
Oops, something went wrong.