|
| 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 | +}); |
0 commit comments