Skip to content

Commit

Permalink
resolve merge conflict manually
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoka committed Sep 25, 2024
1 parent 13e2990 commit 5c45679
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions integration-tests/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ use sp_core::H256;
use sp_core::{RuntimeDebug, U256};
use xcm_emulator::Network;
use xcm_emulator::TestExt;
use crate::polkadot_test_net::BOB;
use crate::polkadot_test_net::UNITS;
use crate::polkadot_test_net::WETH;
use hydradx_runtime::RuntimeEvent;
use hydradx_runtime::System;
use fp_evm::FeeCalculator;
use frame_support::assert_ok;
use test_utils::expect_events;


pub fn deployer() -> EvmAddress {
EVMAccounts::evm_address(&Into::<AccountId>::into(ALICE))
Expand Down Expand Up @@ -66,16 +75,6 @@ fn contract_check_fails_on_eoa() {
});
}

#[test]
fn contract_check_fails_on_precompile_without_code() {
TestNet::reset();
Hydra::execute_with(|| {
let checker = deploy_contract("ContractCheck", deployer());
pallet_evm::AccountCodes::<Runtime>::remove(dai_ethereum_address());
assert_eq!(is_contract(checker, dai_ethereum_address()), false);
});
}

#[test]
fn contract_check_succeeds_on_currencies_precompile() {
TestNet::reset();
Expand Down Expand Up @@ -108,3 +107,45 @@ fn contract_check_succeeds_on_precompile_with_invalid_code() {
assert_eq!(is_contract(checker, dai_ethereum_address()), true);
});
}

#[test]
fn contract_check_should_succeed_when_called_from_extrinsic() {
TestNet::reset();
Hydra::execute_with(|| {
// Arrange
let checker = deploy_contract("ContractCheck", deployer());
let mut data = Into::<u32>::into(Function::Check).to_be_bytes().to_vec();
data.extend_from_slice(H256::from(dai_ethereum_address()).as_bytes());
assert_ok!(EVMAccounts::bind_evm_address(hydradx_runtime::RuntimeOrigin::signed(
BOB.into()
)));
assert_ok!(hydradx_runtime::Currencies::update_balance(
hydradx_runtime::RuntimeOrigin::root(),
BOB.into(),
WETH,
(10_000_000 * UNITS) as i128,
));
/// For reference with code set in storage this always succeeds
// pallet_evm::AccountCodes::<Runtime>::insert(
// dai_ethereum_address(),
// &hex!["365f5f375f5f365f73bebebebebebebebebebebebebebebebebebebebe5af43d5f5f3e5f3d91602a57fd5bf3"][..],
// );

// Act
assert_ok!(hydradx_runtime::EVM::call(
hydradx_runtime::RuntimeOrigin::signed(BOB.into()),
EVMAccounts::evm_address(&Into::<AccountId>::into(BOB)),
checker,
data,
U256::from(0),
1000000,
hydradx_runtime::DynamicEvmFee::min_gas_price().0 * 10,
None,
Some(System::account_nonce(AccountId::from(BOB)).into()),
[].into()
));

// Assert
expect_events::<RuntimeEvent, Runtime>(vec![pallet_evm::Event::Executed { address: checker }.into()]);
});
}

0 comments on commit 5c45679

Please sign in to comment.