Skip to content

Commit

Permalink
Add a basic crowdfunding-esdt test (#143)
Browse files Browse the repository at this point in the history
* Update mx-sdk-rs and add multicontract.ml files.

* Add a crowdfunding-esdt test

* Remove outdated test

* tmp

* Fix deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/storage_reserved.scen.json

* Fix deps/mx-sdk-rs/contracts/examples/adder/scenarios/adder.scen.json

* Fix typo
  • Loading branch information
virgil-serbanuta authored Oct 4, 2023
1 parent 32108d9 commit 7b22f7c
Show file tree
Hide file tree
Showing 22 changed files with 3,651 additions and 14 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,22 @@ By combining pranks with storage access and assertions, we can comprehensively t
To run the tests for your Smart Contracts, ensure that you have fulfilled the following prerequisites:

1. Compile the semantics by executing `make build-foundry`.
2. Compile the contract using `mxpy contract build <path to adder contract>`.
3. Install the `hypothesis` library by running `pip3 install hypothesis`. This library will be utilized for concrete execution with fuzzing.
2. Add a `<path to adder contract>/multicontract.toml` file to the adder contract, something like:
```
[settings]
main = "main"
[contracts.main]
name = "adder"
add-unlabelled = true
allocator = "fail"
stack-size = "1 pages"
```
The stack-size should be as low as possible, while also allowing the contract
to run without errors. Also, if the contract does not need it, the allocator
should be "fail".
3. Compile the contract using `mxpy contract build <path to adder contract>`.
4. Install the `hypothesis` library by running `pip3 install hypothesis`. This library will be utilized for concrete execution with fuzzing.
Now, follow these steps to run the test contract:
Expand Down
2 changes: 1 addition & 1 deletion deps/mx-sdk-rs
Submodule mx-sdk-rs updated 1569 files
2 changes: 1 addition & 1 deletion elrond-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ TODO: Implement [reserved keys and read-only runtimes](https://github.com/Elrond
requires notBool #hasPrefix(KEY, "ELROND")
rule <instrs> #isReservedKey(KEY)
=> #throwException(UserError, "cannot write to storage under Elrond reserved key") ...
=> #throwException(ExecutionFailed, "cannot write to storage under reserved key") ...
</instrs>
requires #hasPrefix(KEY, "ELROND")
Expand Down
8 changes: 5 additions & 3 deletions kmultiversx/src/kmultiversx/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def ListBytes(items: Iterable[KInner]) -> KInner: # noqa: N802
resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))


def mandos_int_to_kint(mandos_int: str) -> KToken:
def mandos_int_to_kint(mandos_int: str, default_when_empty: int | None = None) -> KToken:
if mandos_int == '' and default_when_empty is not None:
return KInt(default_when_empty)
if mandos_int[0:2] == '0x':
return KInt(int(mandos_int, 16))
unseparated_int = mandos_int.replace(',', '')
Expand Down Expand Up @@ -352,7 +354,7 @@ def mandos_to_deploy_tx(tx: dict, filename: str, output_dir: str) -> KInner:
value = mandos_int_to_kint(get_egld_value(tx))
arguments = mandos_arguments_to_klist(tx['arguments'])
gas_limit = mandos_int_to_kint(tx['gasLimit'])
gas_price = mandos_int_to_kint(tx['gasPrice'])
gas_price = mandos_int_to_kint(tx['gasPrice'], default_when_empty=0)

code = get_contract_code(tx['contractCode'], filename)
assert isinstance(code, str)
Expand All @@ -369,7 +371,7 @@ def mandos_to_call_tx(tx: dict) -> KInner:
function = KWasmString(tx['function'])
arguments = mandos_arguments_to_klist(tx['arguments'])
gas_limit = mandos_int_to_kint(tx['gasLimit'])
gas_price = mandos_int_to_kint(tx['gasPrice'])
gas_price = mandos_int_to_kint(tx['gasPrice'], default_when_empty=0)

return KApply('callTx', [sender, to, value, esdt_value, function, arguments, gas_limit, gas_price])

Expand Down
6 changes: 3 additions & 3 deletions src/testapi/src/testapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
nonce: i64,
balanceHandle: i32,
);

fn registerNewAddress(
ownerHandle: i32,
nonce: i64,
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn deploy_contract<M: ManagedTypeApi>(
) -> ManagedAddress<M> {
unsafe {
let mut dest = ManagedAddress::zero();

deployContract(
owner.get_raw_handle(),
gas_limit as i64,
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn get_storage<M: ManagedTypeApi>(
) -> ManagedBuffer<M> {
unsafe {
let mut dest = ManagedBuffer::new();

getStorage(
address.get_raw_handle(),
key.get_raw_handle(),
Expand Down
2 changes: 0 additions & 2 deletions tests/alloc_features.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/boxed_bytes_zeros.scen.json
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/crypto_keccak256_legacy_alloc.scen.json
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/crypto_sha256_legacy_alloc.scen.json
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/echo_async_result_empty.scen.json
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/echo_big_int_nested_alloc.scen.json
deps/mx-sdk-rs/contracts/feature-tests/alloc-features/scenarios/echo_boxed_bytes.scen.json
Expand Down
2 changes: 0 additions & 2 deletions tests/basic_features.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/big_uint_to_u64.
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/block_info.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/codec_err.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/count_ones.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/crypto_keccak256_legacy_managed.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/crypto_keccak256.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/crypto_sha256_legacy_managed.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/crypto_sha256.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/echo_array_u8.scen.json
deps/mx-sdk-rs/contracts/feature-tests/basic-features/scenarios/echo_arrayvec.scen.json
Expand Down
8 changes: 8 additions & 0 deletions tests/contracts/foundrylike/multicontract.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
main = "main"

[contracts.main]
name = "foundrylike"
add-unlabelled = true
allocator = "fail"
stack-size = "1 pages"
7 changes: 7 additions & 0 deletions tests/contracts/test_crowdfunding-esdt/.gitignore
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*/
Loading

0 comments on commit 7b22f7c

Please sign in to comment.