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
test: assets precompile using eth address as default example
  • Loading branch information
Daanvdplas committed Nov 25, 2025
commit ab1d6cb5e7b08902c6f82cbc36e64cf8503e505c
36 changes: 36 additions & 0 deletions integration-tests/public/assets-precompile-eth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "assets_precompile_eth"
version = "6.0.0-beta.1"
authors = ["Use Ink <[email protected]>"]
edition = "2024"
publish = false

[dependencies]
ink = { path = "../../../crates/ink", default-features = false }
ink_precompiles = { path = "../../../crates/precompiles", default-features = false }

[dev-dependencies]
ink_e2e = { path = "../../../crates/e2e" }
ink_sandbox = { path = "../../../crates/sandbox" }
hex = "0.4"

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"ink_precompiles/std",
]
ink-as-dependency = []
e2e-tests = []

[package.metadata.ink-lang]
abi = "ink"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(ink_abi, values("ink", "sol", "all"))'
]
87 changes: 87 additions & 0 deletions integration-tests/public/assets-precompile-eth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Assets Precompile Integration Test (Ethereum-First Approach)

This integration test demonstrates the **recommended approach** for interacting with pallet-revive contracts using Ethereum addresses as the default.

## Why Ethereum Addresses?

When using Substrate addresses (AccountId32) with pallet-revive, you encounter the "fallback account trap":

```
Substrate AccountId32 (Alice)
▼ keccak_256()[12..]
Derived H160 (0xabcd...)
▼ Contract stores this address
▼ Later: Contract needs to send tokens back
▼ to_account_id(0xabcd...) lookup
├─ IF MAPPED: Returns original AccountId32 ✓
└─ IF NOT MAPPED: Returns FALLBACK account ✗
(0xabcd...EEEEEEEEEEEEEEEEEEEE)
Tokens are effectively lost!
```

## The Ethereum-First Solution

By using Ethereum keypairs (ECDSA/secp256k1), the address roundtrip is **lossless**:

```
Ethereum H160 (0x1234...)
▼ to_account_id()
Fallback AccountId32 (0x1234...EEEEEEEEEEEEEEEEEEEE)
▼ to_address() checks is_eth_derived()
▼ TRUE → strips 0xEE suffix
Original H160 (0x1234...) ✓
```

## Key Differences from Standard Approach

| Aspect | Substrate Approach | Ethereum Approach |
|--------|-------------------|-------------------|
| Keypair type | Sr25519 (`alice()`, `bob()`) | ECDSA (`alith()`, `baltathar()`) |
| Address type | Derived H160 | Native H160 |
| Mapping required | Yes (`map_account()`) | **No!** |
| Address roundtrip | Lossy without mapping | Lossless |
| MetaMask compatible | No | Yes |

## Usage

```rust
use ink_e2e::eth::{alith, baltathar};

// Use Ethereum keypairs
let alice = alith();
let bob = baltathar();

// Get native H160 addresses
let alice_address = alice.address();
let bob_address = bob.address();

// No mapping needed - just use them directly with contracts!
```

## Available Dev Accounts

The following Ethereum dev accounts are available via `ink_e2e::eth::dev`:

- `alith()` - Primary test account
- `baltathar()` - Secondary test account
- `charleth()` - Third test account
- `dorothy()` - Fourth test account
- `ethan()` - Fifth test account
- `faith()` - Sixth test account
- ... and more

## Running the Tests

```bash
cargo test -p assets_precompile_eth --features e2e-tests
```
Loading
Loading