Skip to content

Commit

Permalink
fixed build when an endpoint's parameter is called "contract_address"
Browse files Browse the repository at this point in the history
  • Loading branch information
gfusee committed Nov 8, 2023
1 parent 3c497ab commit 8f2af64
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 15 deletions.
81 changes: 74 additions & 7 deletions .novax/abis/tester-contract.abi.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"buildInfo": {
"rustc": {
"version": "1.74.0-nightly",
"commitHash": "ec08a0337f3556212525dbf1d3b41e19bdf27621",
"commitDate": "2023-09-04",
"version": "1.72.0-nightly",
"commitHash": "36fb58e433c782e27dd41034284e157cf86d587f",
"commitDate": "2023-06-26",
"channel": "Nightly",
"short": "rustc 1.74.0-nightly (ec08a0337 2023-09-04)"
"short": "rustc 1.72.0-nightly (36fb58e43 2023-06-26)"
},
"contractCrate": {
"name": "tester-contract",
"version": "0.0.0"
"version": "0.0.0",
"gitVersion": "0.0.8-1-g3c497ab"
},
"framework": {
"name": "multiversx-sc",
"version": "0.43.3"
"version": "0.43.4"
}
},
"name": "Tester",
Expand Down Expand Up @@ -74,6 +75,21 @@
}
]
},
{
"name": "returnContractAddress",
"mutability": "mutable",
"inputs": [
{
"name": "contract_address",
"type": "Address"
}
],
"outputs": [
{
"type": "Address"
}
]
},
{
"name": "returnBiguint",
"mutability": "mutable",
Expand Down Expand Up @@ -479,10 +495,61 @@
"multi_result": true
}
]
},
{
"name": "callAnotherContractReturnTwoU64",
"mutability": "mutable",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": [
{
"type": "u64"
},
{
"type": "u64"
}
]
},
{
"name": "asyncCallAnotherContractReturnTwoU64NoCallback",
"mutability": "mutable",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": []
},
{
"name": "asyncCallAnotherContractReturnTwoU64WithReturningCallback",
"mutability": "mutable",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": []
},
{
"name": "asyncCallAnotherContractReturnTwoU64WithNonReturningCallback",
"mutability": "mutable",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": []
}
],
"events": [],
"hasCallback": false,
"hasCallback": true,
"types": {
"CustomEnum": {
"type": "enum",
Expand Down
Binary file modified .novax/tester-contract.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions abi-build/src/generator/impl_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ fn impl_abi_endpoint_call_query(contract_info_name: &str, abi_endpoint: &AbiEndp
let (endpoint_args_let_statements, endpoint_args_inputs) = impl_endpoint_args_for_call(&abi_endpoint.inputs, abi_types)?;

let common_token = quote! {
let contract_address: AddressValue = (&Address::from(&self.contract_address)).into();
let mut _novax_contract = #contract_info_ident::new(&contract_address); // unnecessary clone when calling
let _novax_contract_address_value: AddressValue = (&Address::from(&self.contract_address)).into();
let mut _novax_contract = #contract_info_ident::new(&_novax_contract_address_value); // unnecessary clone when calling

#endpoint_args_let_statements

Expand Down Expand Up @@ -619,7 +619,7 @@ fn impl_endpoint_key_for_query(endpoint_name: &str, abi_inputs: &AbiInputs) -> T
}
quote! {
let mut _novax_hasher = DefaultHasher::new();
contract_address.value.hash(&mut _novax_hasher);
_novax_contract_address_value.value.hash(&mut _novax_hasher);
#endpoint_name.hash(&mut _novax_hasher);
#(#inputs_hash_idents)*
let _novax_key = _novax_hasher.finish();
Expand Down
6 changes: 6 additions & 0 deletions tester/contract/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pub trait PrinterModule: ContractBase {
ManagedBuffer::from("test")
}

// there was a bug when an endpoint's parameter is called "contract_address"
#[endpoint(returnContractAddress)]
fn return_contract_address(&self, contract_address: ManagedAddress<Self::Api>) -> ManagedAddress<Self::Api> {
contract_address
}

#[endpoint(returnBiguint)]
fn return_biguint(&self) -> BigUint<Self::Api> {
BigUint::from(10u8).pow(18)
Expand Down
9 changes: 6 additions & 3 deletions tester/contract/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 41
// Endpoints: 42
// Async Callback: 1
// Total number of exported functions: 43
// Total number of exported functions: 44

#![no_std]
#![allow(internal_features)]

// Configuration that works with rustc < 1.73.0.
// TODO: Recommended rustc version: 1.73.0 or newer.
#![feature(lang_items)]

multiversx_sc_wasm_adapter::allocator!();
Expand All @@ -25,6 +27,7 @@ multiversx_sc_wasm_adapter::endpoints! {
noArgNoReturnEndpoint => no_arg_no_return_endpoint
returnCaller => return_caller
returnManagedBuffer => return_managed_buffer
returnContractAddress => return_contract_address
returnBiguint => return_biguint
returnU8 => return_u8
returnU16 => return_u16
Expand Down
4 changes: 2 additions & 2 deletions tester/core/tests/dummy_deploy.rs

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tester/core/tests/mock_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ async fn test_call_buffer_result() -> Result<(), NovaXError> {
Ok(())
}

#[tokio::test]
async fn test_call_contract_address_result() -> Result<(), NovaXError> {
let executor = get_executor();

let result = TesterContract::new(
TESTER_CONTRACT_ADDRESS
)
.call(executor, 600000000)
.return_contract_address(&TESTER_CONTRACT_ADDRESS.into())
.await?;

let expected: Address = TESTER_CONTRACT_ADDRESS.into();

assert_eq!(result.result.unwrap(), expected);

Ok(())
}

#[tokio::test]
async fn test_call_biguint_result() -> Result<(), NovaXError> {
let executor = get_executor();
Expand Down

0 comments on commit 8f2af64

Please sign in to comment.