Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: use eth address as default in e2e 1/2
  • Loading branch information
Daanvdplas committed Nov 26, 2025
commit fc6bc583d6331cb6af60f214070011fdf5182479
2 changes: 2 additions & 0 deletions crates/sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub use {
},
},
frame_system,
// Re-export subxt_signer for Ethereum dev accounts in genesis
ink_e2e::subxt_signer,
ink_precompiles,
pallet_assets,
pallet_assets_precompiles,
Expand Down
28 changes: 24 additions & 4 deletions crates/sandbox/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,36 @@ mod construct_runtime {
pub const INITIAL_BALANCE: u128 = 1_000_000_000_000_000;
pub const DEFAULT_ACCOUNT: AccountId32 = AccountId32::new([1u8; 32]);

/// Convert an Ethereum dev keypair to an AccountId32 using the fallback format.
/// Format: [H160 (20 bytes)][0xEE repeated 12 times]
fn eth_dev_account(keypair: &$crate::subxt_signer::eth::Keypair) -> AccountId32 {
let eth_address = keypair.public_key().to_account_id();
let mut account_bytes = [0xEE_u8; 32];
account_bytes[..20].copy_from_slice(&eth_address.0);
AccountId32::from(account_bytes)
}

pub struct $sandbox {
ext: $crate::TestExternalities,
}

impl ::std::default::Default for $sandbox {
fn default() -> Self {
let ext = $crate::macros::BlockBuilder::<$runtime>::new_ext(vec![(
DEFAULT_ACCOUNT,
INITIAL_BALANCE,
)]);
use $crate::subxt_signer::eth::dev::{alith, baltathar, charleth, dorothy, ethan, faith};

// Fund both the default account and Ethereum dev accounts
let balances = vec![
(DEFAULT_ACCOUNT, INITIAL_BALANCE),
// Ethereum dev accounts (fallback format: [H160][0xEE; 12])
(eth_dev_account(&alith()), INITIAL_BALANCE),
(eth_dev_account(&baltathar()), INITIAL_BALANCE),
(eth_dev_account(&charleth()), INITIAL_BALANCE),
(eth_dev_account(&dorothy()), INITIAL_BALANCE),
(eth_dev_account(&ethan()), INITIAL_BALANCE),
(eth_dev_account(&faith()), INITIAL_BALANCE),
];

let ext = $crate::macros::BlockBuilder::<$runtime>::new_ext(balances);
Self { ext }
}
}
Expand Down
44 changes: 15 additions & 29 deletions integration-tests/public/assets-precompile-eth/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,20 @@ mod e2e_tests {
use ink_e2e::{
ContractsBackend,
IntoAddress,
// Sr25519 keypairs for test infrastructure signing
// Sr25519 keypair for transaction signing (required by test infrastructure)
alice,
// Ethereum keypairs for addresses
eth::{
alith,
baltathar,
charleth,
},
};
use ink_sandbox::{
AccountId32,
DefaultSandbox,
E2EError,
IntoAccountId,
SandboxClient,
api::prelude::{
AssetsAPI,
BalanceAPI,
},
api::prelude::AssetsAPI,
assert_last_event,
assert_ok,
};
Expand All @@ -271,8 +267,6 @@ mod e2e_tests {
let asset_id: u32 = 1;
let mut constructor = AssetHubPrecompileEthRef::new(asset_id);

// Use alice() for signing, but the contract will be owned by alice's derived
// address
let contract = client
.instantiate("assets_precompile_eth", &alice(), &mut constructor)
.value(1_000_000_000_000u128)
Expand Down Expand Up @@ -381,7 +375,7 @@ mod e2e_tests {
) -> E2EResult<()> {
let asset_id: u32 = 1;

client.sandbox().create(&asset_id, &alice(), 1u128)?;
client.sandbox().create(&asset_id, &alith(), 1u128)?;

let contract = client
.instantiate(
Expand Down Expand Up @@ -444,7 +438,7 @@ mod e2e_tests {
) -> E2EResult<()> {
let asset_id: u32 = 1;

client.sandbox().create(&asset_id, &alice(), 1u128)?;
client.sandbox().create(&asset_id, &alith(), 1u128)?;

let contract = client
.instantiate(
Expand Down Expand Up @@ -512,10 +506,6 @@ mod e2e_tests {
) -> E2EResult<()> {
let asset_id: u32 = 1;

// Fund the alith account with native tokens (needed for transaction fees)
let alith_account: AccountId32 = (&alith()).into_account_id();
BalanceAPI::mint_into(client.sandbox(), &alith_account, 1_000_000_000_000u128)?;

client.sandbox().create(&asset_id, &alith(), 1u128)?;

let contract = client
Expand Down Expand Up @@ -556,10 +546,6 @@ mod e2e_tests {
) -> E2EResult<()> {
let asset_id: u32 = 1;

// Fund the alith account with native tokens (needed for transaction fees)
let alith_account: AccountId32 = (&alith()).into_account_id();
BalanceAPI::mint_into(client.sandbox(), &alith_account, 1_000_000_000_000u128)?;

client.sandbox().create(&asset_id, &alith(), 1u128)?;

let contract = client
Expand All @@ -571,47 +557,47 @@ mod e2e_tests {
.submit()
.await?;

// Mint to alith and approve the contract to spend
AssetsAPI::mint_into(client.sandbox(), &asset_id, &alith(), 100_000u128)?;
// Mint to charleth and approve the contract to spend
AssetsAPI::mint_into(client.sandbox(), &asset_id, &charleth(), 100_000u128)?;
client.sandbox().approve(
&asset_id,
&alith(),
&charleth(),
&contract.account_id,
50_000u128,
)?;

let mut contract_call = contract.call_builder::<AssetHubPrecompileEth>();

// Transfer from alith to baltathar (both Ethereum addresses)
let alith_addr = alith().address();
// Transfer from charleth to baltathar (both Ethereum addresses)
let charleth_addr = charleth().address();
let baltathar_addr = baltathar().address();
let transfer_amount = U256::from(1_500);

let result = client
.call(
&alice(),
&contract_call.transfer_from(alith_addr, baltathar_addr, transfer_amount),
&contract_call.transfer_from(charleth_addr, baltathar_addr, transfer_amount),
)
.submit()
.await?;
assert_ok!(result);
assert_last_event!(
&mut client,
Transfer {
from: alith_addr,
from: charleth_addr,
to: baltathar_addr,
value: transfer_amount,
}
);

// Verify balances using sandbox
let alith_balance = client.sandbox().balance_of(&asset_id, &alith());
let charleth_balance = client.sandbox().balance_of(&asset_id, &charleth());
let baltathar_balance = client.sandbox().balance_of(&asset_id, &baltathar());
let contract_allowance =
client
.sandbox()
.allowance(&asset_id, &alith(), &contract.account_id);
assert_eq!(alith_balance, 98_500u128);
.allowance(&asset_id, &charleth(), &contract.account_id);
assert_eq!(charleth_balance, 98_500u128);
assert_eq!(baltathar_balance, 1_500u128);
assert_eq!(contract_allowance, 48_500u128);

Expand Down