Skip to content

Commit

Permalink
test(integration): update RLP test to use revive
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwht committed Jan 28, 2025
1 parent 019ad69 commit 4c3f21c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion integration-tests/public/rlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink = { path = "../../../crates/ink", default-features = false }
[dev-dependencies]
ink_e2e = { path = "../../../crates/e2e", features = ["sandbox"] }
ink_sandbox = { path = "../../../crates/e2e/sandbox" }
pallet-contracts = { version = "38.0.0", default-features = false }
pallet-revive = { git = "https://github.com/paritytech/polkadot-sdk", rev = "645878a27115db52e5d63115699b4bbb89034067", default-features = false }
sha3 = { version = "0.10" }

[lib]
Expand Down
55 changes: 31 additions & 24 deletions integration-tests/public/rlp/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use ink_e2e::{
ContractsRegistry,
Keypair,
};
use ink_sandbox::{
api::balance_api::BalanceAPI,
AccountId32,
};
use pallet_contracts::ExecReturnValue;
use ink_sandbox::{api::prelude::*, AccountId32, DefaultSandbox, Sandbox};
use pallet_revive::ExecReturnValue;
use ink::H160;
use ink::primitives::{AccountId, DepositLimit};
use ink_e2e::subxt::tx::Signer;
const STORAGE_DEPOSIT_LIMIT: DepositLimit<u128> = DepositLimit::Unchecked;

#[test]
fn call_rlp_encoded_message() {
Expand All @@ -24,34 +25,39 @@ fn call_rlp_encoded_message() {
)
.unwrap_or_else(|_| panic!("Failed to mint tokens"));

let origin = DefaultSandbox::convert_account_to_origin(AccountId32::from(caller.public_key().0));
sandbox.map_account(origin.clone()).expect("unable to map");

// given
let constructor = RlpRef::new(false);
let params = constructor
.endowment(0u32.into())
.code_hash(ink::primitives::Clear::CLEAR_HASH)
.salt_bytes(Vec::new())
.code_hash(ink::primitives::H256::zero())
.salt_bytes(None)
.params();
let exec_input = params.exec_input();

// TODO: could potentially simplify if helpers are exposed.

let code = contracts.load_code("rlp");
let contract_account_id = <ink_e2e::DefaultSandbox as ink_sandbox::api::contracts_api::ContractAPI>
let contract_addr = <DefaultSandbox as ink_sandbox::api::revive_api::ContractAPI>
::deploy_contract(
&mut sandbox,
code,
0,
ink::scale::Encode::encode(&exec_input),
vec![0u8],
caller.public_key().0.into(),
<ink_e2e::DefaultSandbox as ink_sandbox::Sandbox>::default_gas_limit(),
// salt
None,
origin,
<DefaultSandbox as Sandbox>::default_gas_limit(),
STORAGE_DEPOSIT_LIMIT
)
.result
.expect("sandbox deploy contract failed")
.account_id;
.expect("sandbox deploy contract failed").addr;

let mut contract = ContractSandbox {
sandbox,
contract_account_id,
contract_addr: contract_addr,
};

// set value
Expand All @@ -66,7 +72,7 @@ fn call_rlp_encoded_message() {

struct ContractSandbox {
sandbox: ink_e2e::DefaultSandbox,
contract_account_id: AccountId32,
contract_addr: H160,
}

impl ContractSandbox {
Expand Down Expand Up @@ -98,18 +104,19 @@ impl ContractSandbox {
result.data
}


fn call_raw(&mut self, data: Vec<u8>, caller: Keypair) -> ExecReturnValue {
let origin = DefaultSandbox::convert_account_to_origin(AccountId32::from(caller.public_key().0));
let result =
<ink_e2e::DefaultSandbox as ink_sandbox::api::contracts_api::ContractAPI>
<DefaultSandbox as ink_sandbox::api::revive_api::ContractAPI>
::call_contract(
&mut self.sandbox,
self.contract_account_id.clone(),
0,
data,
caller.public_key().0.into(),
<ink_e2e::DefaultSandbox as ink_sandbox::Sandbox>::default_gas_limit(),
None,
pallet_contracts::Determinism::Enforced,
&mut self.sandbox,
self.contract_addr.clone(),
0,
data,
origin,
<DefaultSandbox as Sandbox>::default_gas_limit(),
STORAGE_DEPOSIT_LIMIT,
)
.result
.expect("sandbox call contract failed");
Expand Down

0 comments on commit 4c3f21c

Please sign in to comment.