Skip to content

Commit 514c469

Browse files
committed
chore: add post dispatch aleo tests
1 parent c3dd479 commit 514c469

4 files changed

Lines changed: 151 additions & 11 deletions

File tree

typescript/aleo-sdk/src/clients/provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ export class AleoProvider implements AltVM.IProvider {
745745
async getCreateMerkleTreeHookTransaction(
746746
_req: AltVM.ReqCreateMerkleTreeHook,
747747
): Promise<AleoTransaction> {
748+
// TODO: replace default mailbox id with real one
748749
return {
749750
programName: 'hook_manager.aleo',
750751
functionName: 'init_merkle_tree',

typescript/aleo-sdk/src/tests/2_core.e2e-test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ describe('2. aleo sdk core e2e tests', async function () {
1313
let signer: AltVM.ISigner<AleoTransaction, AleoReceipt>;
1414

1515
let mailboxAddress: string;
16+
let ismAddress: string;
17+
let hookAddress: string;
1618

1719
before(async () => {
1820
const localnetRpc = 'http://localhost:3030';
@@ -21,6 +23,9 @@ describe('2. aleo sdk core e2e tests', async function () {
2123
'APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH';
2224

2325
signer = await AleoSigner.connectWithSigner([localnetRpc], privateKey);
26+
27+
const noopIsm = await signer.createNoopIsm({});
28+
ismAddress = noopIsm.ismAddress;
2429
});
2530

2631
step('create new mailbox', async () => {
@@ -53,8 +58,6 @@ describe('2. aleo sdk core e2e tests', async function () {
5358

5459
step('set mailbox default ism', async () => {
5560
// ARRANGE
56-
const { ismAddress } = await signer.createNoopIsm({});
57-
5861
let mailbox = await signer.getMailbox({ mailboxAddress });
5962
expect(mailbox.defaultIsm).to.be.empty;
6063

@@ -71,13 +74,14 @@ describe('2. aleo sdk core e2e tests', async function () {
7174

7275
step('set mailbox default hook', async () => {
7376
// ARRANGE
74-
const { hookAddress } = await signer.createMerkleTreeHook({
75-
mailboxAddress,
76-
});
77-
7877
let mailbox = await signer.getMailbox({ mailboxAddress });
7978
expect(mailbox.defaultHook).to.be.empty;
8079

80+
const merkleTreeHook = await signer.createMerkleTreeHook({
81+
mailboxAddress: mailbox.address,
82+
});
83+
hookAddress = merkleTreeHook.hookAddress;
84+
8185
// ACT
8286
await signer.setDefaultHook({
8387
mailboxAddress,
@@ -91,10 +95,6 @@ describe('2. aleo sdk core e2e tests', async function () {
9195

9296
step('set mailbox required hook', async () => {
9397
// ARRANGE
94-
const { hookAddress } = await signer.createMerkleTreeHook({
95-
mailboxAddress,
96-
});
97-
9898
let mailbox = await signer.getMailbox({ mailboxAddress });
9999
expect(mailbox.requiredHook).to.be.empty;
100100

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { Account } from '@provablehq/sdk';
2+
import { expect } from 'chai';
3+
import { step } from 'mocha-steps';
4+
5+
import { AltVM } from '@hyperlane-xyz/utils';
6+
7+
import { AleoSigner } from '../clients/signer.js';
8+
import { AleoReceipt, AleoTransaction } from '../utils/types.js';
9+
10+
describe('3. aleo sdk post dispatch e2e tests', async function () {
11+
this.timeout(300_000);
12+
13+
let signer: AltVM.ISigner<AleoTransaction, AleoReceipt>;
14+
15+
let mailboxAddress: string;
16+
let igpAddress: string;
17+
18+
before(async () => {
19+
const localnetRpc = 'http://localhost:3030';
20+
// test private key with funds
21+
const privateKey =
22+
'APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH';
23+
24+
signer = await AleoSigner.connectWithSigner([localnetRpc], privateKey);
25+
26+
const domainId = 1234;
27+
28+
const mailbox = await signer.createMailbox({
29+
domainId: domainId,
30+
defaultIsmAddress: '',
31+
});
32+
mailboxAddress = mailbox.mailboxAddress;
33+
});
34+
35+
step('create new Merkle Tree hook', async () => {
36+
// ARRANGE
37+
38+
// ACT
39+
const txResponse = await signer.createMerkleTreeHook({
40+
mailboxAddress,
41+
});
42+
43+
// ASSERT
44+
expect(txResponse.hookAddress).to.be.not.empty;
45+
46+
let merkle_tree_hook = await signer.getMerkleTreeHook({
47+
hookAddress: txResponse.hookAddress,
48+
});
49+
50+
expect(merkle_tree_hook).not.to.be.undefined;
51+
expect(merkle_tree_hook.address).to.equal(txResponse.hookAddress);
52+
});
53+
54+
step('create new IGP hook', async () => {
55+
// ARRANGE
56+
57+
// ACT
58+
const txResponse = await signer.createInterchainGasPaymasterHook({
59+
denom: '',
60+
});
61+
62+
// ASSERT
63+
expect(txResponse.hookAddress).to.be.not.empty;
64+
65+
let igp = await signer.getInterchainGasPaymasterHook({
66+
hookAddress: txResponse.hookAddress,
67+
});
68+
69+
expect(igp).not.to.be.undefined;
70+
expect(igp.address).to.equal(txResponse.hookAddress);
71+
expect(igp.owner).to.equal(signer.getSignerAddress());
72+
expect(igp.destinationGasConfigs).to.be.empty;
73+
74+
igpAddress = igp.address;
75+
});
76+
77+
step('set destination gas config', async () => {
78+
// ARRANGE
79+
const remoteDomainId = 1234;
80+
const gasOverhead = '200000';
81+
const gasPrice = '1';
82+
const tokenExchangeRate = '10000000000';
83+
84+
let igp = await signer.getInterchainGasPaymasterHook({
85+
hookAddress: igpAddress,
86+
});
87+
expect(Object.keys(igp.destinationGasConfigs)).to.have.lengthOf(0);
88+
89+
// ACT
90+
await signer.setDestinationGasConfig({
91+
hookAddress: igpAddress,
92+
destinationGasConfig: {
93+
remoteDomainId: remoteDomainId,
94+
gasOracle: {
95+
tokenExchangeRate: tokenExchangeRate,
96+
gasPrice: gasPrice,
97+
},
98+
gasOverhead: gasOverhead,
99+
},
100+
});
101+
102+
// ASSERT
103+
igp = await signer.getInterchainGasPaymasterHook({
104+
hookAddress: igpAddress,
105+
});
106+
expect(Object.keys(igp.destinationGasConfigs)).to.have.lengthOf(1);
107+
108+
const gasConfig = igp.destinationGasConfigs[remoteDomainId];
109+
110+
expect(gasConfig.gasOverhead).to.equal(gasOverhead);
111+
expect(gasConfig.gasOracle?.gasPrice).to.equal(gasPrice);
112+
expect(gasConfig.gasOracle?.tokenExchangeRate).to.equal(tokenExchangeRate);
113+
});
114+
115+
step('set igp owner', async () => {
116+
// ARRANGE
117+
const newOwner = new Account().address().to_string();
118+
119+
let igp = await signer.getInterchainGasPaymasterHook({
120+
hookAddress: igpAddress,
121+
});
122+
123+
expect(igp.owner).to.equal(signer.getSignerAddress());
124+
125+
// ACT
126+
await signer.setInterchainGasPaymasterHookOwner({
127+
hookAddress: igpAddress,
128+
newOwner: newOwner,
129+
});
130+
131+
// ASSERT
132+
igp = await signer.getInterchainGasPaymasterHook({
133+
hookAddress: igpAddress,
134+
});
135+
136+
expect(igp.owner).to.equal(newOwner);
137+
});
138+
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// enforce order of test suites
22
// import './1_interchain_security.e2e-test.js';
3-
import './2_core.e2e-test.js';
3+
// import './2_core.e2e-test.js';
4+
import './3_post_dispatch.e2e-test';

0 commit comments

Comments
 (0)