Skip to content

Commit 6417ecb

Browse files
alexander-seicursoragentclaude
authored
Tests: Precompile Tests Phase 3 (PLT-372) (#3985)
## Describe your changes and provide context Phase 3 of the precompile test refactor ([PLT-372](https://linear.app/seilabs/issue/PLT-372/refactor-precompile-tests)), building on the phase 1 framework (#3777) and the phase 2 coverage (#3786). Phase 2 covered the wasm-free precompiles **as they existed then**. Since that merged, `Generate v6.7 precompiles` (#3961), the scoped module authorizations (#3893, #3846) and the module Msg rpc surface (#3825) landed. This phase brings the suite back in line with the deployed interface. ### New specs | Precompile | Spec | Coverage | |---|---|---| | auth (0x…100D) | `auth.spec.ts` | `account` / `accounts` / `params` / `nextAccountNumber`, LCD parity incl. the nested base account module accounts wrap theirs in | | authz (0x…100E) | `authz.spec.ts` | `grants` / `granterGrants` / `granteeGrants`; the non-empty fixture is a `staking.grantStakingAuthorization`, since authz itself cannot grant | | evidence (0x…100F) | `evidence.spec.ts` | `evidence` / `allEvidence` against the module's own list | | mint (0x…1012) | `mint.spec.ts` | `params` / `minter` vs Sei's own `/seichain/mint/v1beta1/...` routes | | params (0x…1013) | `params.spec.ts` | `params(subspace, key)` vs the staking module, plus the unknown/empty subspace reverts | | slashing (0x…1014) | `slashing.spec.ts` | `params` / `signingInfo` / `signingInfos`, grant + revoke of unjail authorization, and the unjail guards | | upgrade (0x…1015) | `upgrade.spec.ts` | `currentPlan` / `appliedPlan` / `upgradedConsensusState` / `moduleVersions` | ### Existing specs extended - **bank** — `spendableBalances`, `totalSupply`, `params`, `denomMetadata` (via a tokenfactory denom), `denomsMetadata` (pages until it reaches that denom, so `nextKey` round-trips). - **staking** — `grantStakingAuthorization` → `delegateWithAuthorization` → Cosmos-side delegation → `revokeStakingAuthorization` → reverts; `redelegate`/`undelegateWithAuthorization`; and the remaining query surface (`validators`, `validatorDelegations`, `unbondingDelegation`, `delegatorDelegations`, `redelegations`, `historicalInfo`, …). - **gov** — vote and proposal authorizations (`grant`/`voteWithAuthorization`/`submitProposalWithAuthorization`/`revoke`), plus `proposal`, `proposals`, `getVote`, `votes`, `params`, `getDeposit`, `deposits`, `tallyResult`. - **distribution** — `withdrawValidatorCommission`, the withdraw authorizations, and `params`, `validatorOutstandingRewards`, `validatorCommission`, `validatorSlashes`, `delegationRewards`, `delegatorValidators`, `delegatorWithdrawAddress`, `communityPool`. ### Framework - New addresses on `PRECOMPILE_ADDRESSES`. - `cosmosUtils.cosmosRest` — an LCD reader for the modules cosmjs does not wrap (mint, params, upgrade, evidence, slashing, authz, auth). Every path was taken from the module's decoded `pb.gw.go` gateway pattern rather than guessed, and every response field from its proto tag; the API server marshals with `OrigName` + `EmitDefaults`, so the reads are snake_case. - Bootstrap pool 48 → 80, with the `claimPool` budget (29) recorded next to it — a non-blocking note from the phase 2 review. Out of scope, unchanged: wasm-gated flows (wasmd, pointer `addCW*`, solo), the ibc precompile, and feegrant (0x…1010), which is not registered and whose module was removed in #3958. oracle stays the phase 2 retirement assertion. ## Testing performed to validate your change - `npx tsc --noEmit` clean; no lint errors. - Every assertion was reviewed against the Go executor and the sei-cosmos keeper behind it rather than against assumption. That pass corrected, among others: `historicalInfo` pinning an unreachable executor fallback instead of the querier's `historical info for height %d not found`; `nextAccountNumber` reading `next_account_number` where the response field is `count`; and mint's LCD path, which was three guesses deep with the real route last. - It also removed tests that could not fail — a `historicalInfo` try/catch asserting success in both branches, `evidence` hardcoding an empty chain in four places, `authz` index-matching expirations across two independently ordered lists, `bank.denomsMetadata` asserting only "is an array" — and replaced receipt-only verification of the authorized reward withdrawal with the `DelegationRewardsWithdrawn` credit its non-authz sibling already pins. **Not yet run against a live cluster.** The remaining risk is concentrated in real chain responses, so this wants a `make docker-cluster-start` + `npm run precompile:ci` run before merge; I will post the result on this PR. 🤖 Generated with [Cursor](https://cursor.com) Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 9115b06 commit 6417ecb

17 files changed

Lines changed: 2401 additions & 11 deletions

‎integration_test/precompile_tests/README.md‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ balances, associations, …) over RPC/REST. For every precompile, the spec file
4545
ABIs are loaded from the repo's own `precompiles/<name>/abi.json` (the files the
4646
chain binary embeds), so specs can never drift from the deployed interface.
4747

48-
### Current coverage (phases 1–2, wasm-free)
48+
### Current coverage (phases 1–3, wasm-free)
4949

5050
| Precompile | Spec |
5151
|---|---|
@@ -58,11 +58,20 @@ chain binary embeds), so specs can never drift from the deployed interface.
5858
| oracle (0x…1008) | `precompiles/oracle.spec.ts` (retirement assertion) |
5959
| pointerview (0x…100A) | `precompiles/pointerview.spec.ts` |
6060
| pointer (0x…100b) | `precompiles/pointer.spec.ts` (retirement assertion) |
61+
| auth (0x…100D) | `precompiles/auth.spec.ts` |
62+
| authz (0x…100E) | `precompiles/authz.spec.ts` |
63+
| evidence (0x…100F) | `precompiles/evidence.spec.ts` |
6164
| p256 (0x…1011) | `precompiles/p256.spec.ts` |
65+
| mint (0x…1012) | `precompiles/mint.spec.ts` |
66+
| params (0x…1013) | `precompiles/params.spec.ts` |
67+
| slashing (0x…1014) | `precompiles/slashing.spec.ts` |
68+
| upgrade (0x…1015) | `precompiles/upgrade.spec.ts` |
6269

63-
Planned next: wasm-gated flows (wasmd, solo CW claims) in a separate `wasm/`
64-
spec dir behind a live `isWasmEnabled()` check, since wasm deployments are
65-
blocked on production chains. The ibc precompile is out of scope.
70+
Phase 3 (PLT-372) covers the v6.7 non-wasm precompiles and the post-phase-2
71+
methods on bank/staking/gov/distribution (query surface + scoped authz).
72+
Wasm-gated flows (wasmd, solo CW claims) stay in a later `wasm/` spec dir
73+
behind a live `isWasmEnabled()` check. The ibc precompile and the
74+
unregistered feegrant precompile (0x…1010) are out of scope.
6675

6776
Hard-won facts encoded in these specs (read before writing a new one):
6877

@@ -173,7 +182,6 @@ accounts.
173182
| --- | --- |
174183
| `SEI_EVM_RPC` | `http://localhost:8545` |
175184
| `SEI_COSMOS_RPC` | `http://localhost:26657` |
176-
| `SEI_REST` | `http://localhost:1317` |
177185
| `SEI_ADMIN_MNEMONIC` | unset (a random admin is minted and funded via the docker devnet) |
178186
| `PRECOMPILE_TESTS_RUNTIME_STATE` | `runtime/runtime.json` |
179187
| `PRECOMPILE_POLLING_INTERVAL_MS` | `100` (Sei blocks are ~400ms; ethers default 4s is too slow) |

‎integration_test/precompile_tests/_start/00_bootstrap.spec.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ import { fundAdminOnSei, generateMnemonic, seiAddressFromMnemonic } from '../uti
2020
import { writeRuntimeState, RuntimeState } from '../utils/testUtils';
2121
import { ADDRESS } from '../utils/format';
2222

23-
const POOL_SIZE = 48;
23+
/**
24+
* Size of the single-use account pool. Demand is the sum of every `claimPool`
25+
* count across `precompiles/`, which phase 3 leaves at 29:
26+
*
27+
* rg -o 'claimPool\(runtime, provider, (\d+)' -r '$1' precompiles | paste -sd+ | bc
28+
*
29+
* The headroom is deliberate — exhaustion throws from `claimPool` partway
30+
* through a run, so it is cheaper to over-fund than to re-bootstrap.
31+
*/
32+
const POOL_SIZE = 80;
2433
const POOL_FUND_WEI = ethers.parseEther('5');
2534

2635
describe('precompile_tests bootstrap', function () {

‎integration_test/precompile_tests/config/endpoints.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const Endpoints = {
77
sei: {
88
evmRpc: env('SEI_EVM_RPC', 'http://localhost:8545'),
99
cosmosRpc: env('SEI_COSMOS_RPC', 'http://localhost:26657'),
10-
rest: env('SEI_REST', 'http://localhost:1317'),
1110
},
1211
} as const;
1312

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/**
2+
* auth precompile (0x…100D) — account queries against a live Sei chain.
3+
*
4+
* All four methods are views. The parity oracle is the auth module's own Query
5+
* service; the Go executor has no delegatecall guard (unlike staking/gov), so
6+
* CALL, STATICCALL and DELEGATECALL all succeed.
7+
*
8+
* `nextAccountNumber` queries a keeper method that increments the persisted
9+
* counter, which the executor neutralises by branching a CacheContext. That
10+
* discard is not observable from here — an `eth_call` commits nothing either
11+
* way — so it stays pinned by auth_test.go:TestNextAccountNumber, and this
12+
* spec only asserts the value the chain actually reports.
13+
*/
14+
import { ethers } from 'ethers';
15+
import { expect } from 'chai';
16+
import { seiRpc, rawSei } from '../utils/chainUtils';
17+
import { EvmAccount } from '../utils/evmUtils';
18+
import {
19+
authAccount,
20+
authAccounts,
21+
authNextAccountNumber,
22+
authParams,
23+
baseAccount,
24+
} from '../utils/moduleQueries';
25+
import {
26+
PRECOMPILE_ADDRESSES,
27+
precompileContract,
28+
precompileInterface,
29+
callerContract,
30+
expectExecutionReverted,
31+
} from '../utils/precompileUtils';
32+
import { readRuntimeState, RuntimeState } from '../utils/testUtils';
33+
34+
const empty = new Uint8Array();
35+
36+
const uint64 = (v: string | number | bigint | undefined): bigint => BigInt(v ?? 0);
37+
38+
describe('auth precompile (0x100D)', function () {
39+
this.timeout(120 * 1000);
40+
41+
const provider = seiRpc();
42+
const authIface = precompileInterface('auth');
43+
44+
let runtime: RuntimeState;
45+
let admin: EvmAccount;
46+
let auth: ethers.Contract;
47+
let caller: ethers.Contract;
48+
49+
before(() => {
50+
runtime = readRuntimeState();
51+
admin = EvmAccount.fromMnemonic(runtime.funded.adminMnemonic, provider);
52+
auth = precompileContract('auth', admin.wallet);
53+
caller = callerContract(runtime, admin.wallet);
54+
});
55+
56+
describe('happy path & state parity', () => {
57+
it('account(admin) matches the module address, account_number and sequence', async () => {
58+
const sei = admin.seiAddress();
59+
const [via, stored] = await Promise.all([
60+
auth.account(admin.address),
61+
authAccount(sei),
62+
]);
63+
expect(stored, 'the auth module must know the admin account').to.not.equal(undefined);
64+
const expected = baseAccount(stored!);
65+
expect(via.accountAddress).to.equal(sei);
66+
expect(via.accountAddress).to.equal(expected.address);
67+
expect(via.accountNumber).to.equal(uint64(expected.account_number));
68+
expect(via.sequence).to.equal(uint64(expected.sequence));
69+
});
70+
71+
it('accounts(empty) returns the same first page as the auth module', async () => {
72+
const [page, stored] = await Promise.all([auth.accounts(empty), authAccounts()]);
73+
expect(page.accounts.length, 'first page of auth accounts').to.be.greaterThan(0);
74+
// Both read the first page with the module's default page size, so the
75+
// rows must line up in order, not merely in count.
76+
expect(
77+
[...page.accounts].map((a: { accountAddress: string }) => a.accountAddress),
78+
'accounts() first page vs the auth module',
79+
).to.deep.equal(stored.map(a => baseAccount(a).address));
80+
});
81+
82+
it('params() matches the auth module', async () => {
83+
const [via, p] = await Promise.all([auth.params(), authParams()]);
84+
expect(p, 'the auth module must report params').to.not.equal(undefined);
85+
expect(via.maxMemoCharacters).to.equal(uint64(p!.max_memo_characters));
86+
expect(via.txSigLimit).to.equal(uint64(p!.tx_sig_limit));
87+
expect(via.txSizeCostPerByte).to.equal(uint64(p!.tx_size_cost_per_byte));
88+
expect(via.sigVerifyCostEd25519).to.equal(uint64(p!.sig_verify_cost_ed25519));
89+
expect(via.sigVerifyCostSecp256k1).to.equal(uint64(p!.sig_verify_cost_secp256k1));
90+
expect(via.disableSeqnoCheck).to.equal(Boolean(p!.disable_seqno_check));
91+
});
92+
93+
it('nextAccountNumber() matches the auth module and is past the admin account', async () => {
94+
const [count, next, account] = await Promise.all([
95+
auth.nextAccountNumber() as Promise<bigint>,
96+
authNextAccountNumber(),
97+
auth.account(admin.address),
98+
]);
99+
expect(count, 'nextAccountNumber vs the auth module').to.equal(uint64(next));
100+
expect(count > account.accountNumber, 'next number is past every issued number').to.equal(
101+
true,
102+
);
103+
});
104+
});
105+
106+
describe('error handling', () => {
107+
it('account of a never-associated random EVM address reverts (eth_call)', async () => {
108+
await expectExecutionReverted(
109+
auth.account(EvmAccount.random(provider).address),
110+
'auth.account of a never-associated EVM address',
111+
);
112+
});
113+
114+
it('view methods reject value (eth_call with value 0x1)', async () => {
115+
const cases: Array<[string, unknown[]]> = [
116+
['account', [admin.address]],
117+
['accounts', [empty]],
118+
['params', []],
119+
['nextAccountNumber', []],
120+
];
121+
for (const [method, args] of cases) {
122+
const envelope = await rawSei('eth_call', [
123+
{
124+
from: admin.address,
125+
to: PRECOMPILE_ADDRESSES.auth,
126+
data: authIface.encodeFunctionData(method, args),
127+
value: '0x1',
128+
},
129+
'latest',
130+
]);
131+
expect(envelope.error, `${method} with value must revert`).to.not.equal(undefined);
132+
expect(envelope.error!.message).to.match(/execution reverted|revert/i);
133+
}
134+
});
135+
});
136+
137+
describe('dispatch semantics (via PrecompileCaller)', () => {
138+
it('account and params respond through a real CALL from contract bytecode', async () => {
139+
const accountData = authIface.encodeFunctionData('account', [admin.address]);
140+
const paramsData = authIface.encodeFunctionData('params', []);
141+
const [accountRet, paramsRet, directAccount, directParams] = await Promise.all([
142+
caller.callTarget.staticCall(PRECOMPILE_ADDRESSES.auth, accountData) as Promise<string>,
143+
caller.callTarget.staticCall(PRECOMPILE_ADDRESSES.auth, paramsData) as Promise<string>,
144+
auth.account(admin.address),
145+
auth.params(),
146+
]);
147+
const [decodedAccount] = authIface.decodeFunctionResult('account', accountRet);
148+
const [decodedParams] = authIface.decodeFunctionResult('params', paramsRet);
149+
expect(decodedAccount.accountAddress).to.equal(directAccount.accountAddress);
150+
expect(decodedAccount.accountNumber).to.equal(directAccount.accountNumber);
151+
expect(decodedAccount.sequence).to.equal(directAccount.sequence);
152+
expect(decodedParams.maxMemoCharacters).to.equal(directParams.maxMemoCharacters);
153+
expect(decodedParams.txSigLimit).to.equal(directParams.txSigLimit);
154+
});
155+
156+
it('account and params respond under STATICCALL', async () => {
157+
const accountData = authIface.encodeFunctionData('account', [admin.address]);
158+
const paramsData = authIface.encodeFunctionData('params', []);
159+
const [accountRet, paramsRet, directAccount, directParams] = await Promise.all([
160+
caller.staticcallTarget.staticCall(
161+
PRECOMPILE_ADDRESSES.auth,
162+
accountData,
163+
) as Promise<string>,
164+
caller.staticcallTarget.staticCall(
165+
PRECOMPILE_ADDRESSES.auth,
166+
paramsData,
167+
) as Promise<string>,
168+
auth.account(admin.address),
169+
auth.params(),
170+
]);
171+
const [decodedAccount] = authIface.decodeFunctionResult('account', accountRet);
172+
const [decodedParams] = authIface.decodeFunctionResult('params', paramsRet);
173+
expect(decodedAccount.accountAddress).to.equal(directAccount.accountAddress);
174+
expect(decodedParams.maxMemoCharacters).to.equal(directParams.maxMemoCharacters);
175+
});
176+
177+
it('responds under DELEGATECALL (auth has no delegatecall guard)', async () => {
178+
const data = authIface.encodeFunctionData('account', [admin.address]);
179+
const ret: string = await caller.delegatecallTarget.staticCall(
180+
PRECOMPILE_ADDRESSES.auth,
181+
data,
182+
);
183+
const [decoded] = authIface.decodeFunctionResult('account', ret);
184+
expect(decoded.accountAddress).to.equal(admin.seiAddress());
185+
});
186+
});
187+
});

0 commit comments

Comments
 (0)