@argonprotocol/testing 1.4.12-dev.8cae3588 → 1.4.12-dev.dd86fab9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _argonprotocol_mainchain from '@argonprotocol/mainchain';
2
- import { KeyringPair, ArgonClient, EthereumReceipt, EthereumBeaconHeaderDetailsResponse, EthereumBeaconBlockResponse, EvmContracts, IArgonQueryable } from '@argonprotocol/mainchain';
2
+ import { KeyringPair, ArgonClient, GenericEvent, SubmittableExtrinsic, EthereumReceipt, EthereumBeaconHeaderDetailsResponse, EthereumBeaconBlockResponse, EvmContracts, IArgonQueryable } from '@argonprotocol/mainchain';
3
3
  import { Client } from 'pg';
4
4
  import * as viem from 'viem';
5
5
  import { Hex, createWalletClient, defineChain, Address, ContractFunctionArgs } from 'viem';
@@ -189,6 +189,14 @@ declare function startNetwork(testName: string, options?: {
189
189
  notaryUrl: string;
190
190
  }>;
191
191
 
192
+ type TestTxResult = {
193
+ blockHash: string;
194
+ events: GenericEvent[];
195
+ finalFee?: bigint;
196
+ };
197
+ /** Sign a test transaction and resolve once it is included successfully in a block. */
198
+ declare function submitTx(client: ArgonClient, tx: SubmittableExtrinsic, signer: KeyringPair): Promise<TestTxResult>;
199
+
192
200
  declare function signGatewayPermit(args: {
193
201
  account: ReturnType<typeof privateKeyToAccount>;
194
202
  chainId: number;
@@ -291,20 +299,20 @@ declare class EthereumProofE2eHarness {
291
299
  };
292
300
  proofRelayerUri: string;
293
301
  }): Promise<EthereumProofE2eHarness>;
294
- submit(tx: unknown, signer: KeyringPair): Promise<_argonprotocol_mainchain.TxResult>;
295
- sudoSubmit(tx: unknown): Promise<_argonprotocol_mainchain.TxResult>;
302
+ submit(tx: SubmittableExtrinsic, signer: KeyringPair): Promise<TestTxResult>;
303
+ sudoSubmit(tx: SubmittableExtrinsic): Promise<TestTxResult>;
296
304
  syncVerifierThrough(minimumExecutionBlockNumber: bigint): Promise<void>;
297
305
  proveGatewayActivity(gatewayAddress: Hex, throughExecutionBlockNumber: bigint): Promise<{
298
306
  payload: _argonprotocol_mainchain.EthereumGatewayActivityProofPayload;
299
- result: _argonprotocol_mainchain.TxResult;
307
+ result: TestTxResult;
300
308
  }>;
301
309
  configureEthereumRuntime(gateway: TestMintingGateway, mode: RuntimeSetupMode): Promise<{
302
- result: _argonprotocol_mainchain.TxResult;
310
+ result: TestTxResult;
303
311
  }>;
304
- fundBurnAccount(amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
305
- fundProofRelayer(amount?: bigint): Promise<_argonprotocol_mainchain.TxResult>;
306
- forceSetBalance(address: string, amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
307
- forceSetOwnership(address: string, amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
312
+ fundBurnAccount(amount: bigint): Promise<TestTxResult>;
313
+ fundProofRelayer(amount?: bigint): Promise<TestTxResult>;
314
+ forceSetBalance(address: string, amount: bigint): Promise<TestTxResult>;
315
+ forceSetOwnership(address: string, amount: bigint): Promise<TestTxResult>;
308
316
  waitForExecutionFinalizedAfter(minimumExecutionBlockNumber: bigint): Promise<viem.TransactionReceipt>;
309
317
  }
310
318
  declare class TestMintingGateway {
@@ -375,9 +383,9 @@ declare class TestMintingAuthorityActor {
375
383
  freeBalance: bigint;
376
384
  ownershipBalance: bigint;
377
385
  committedArgonots: bigint;
378
- bitcoinXpub: string;
386
+ bitcoinXpubBytesHex: string;
379
387
  }): Promise<void>;
380
- registerCouncilSigner(): Promise<_argonprotocol_mainchain.TxResult>;
388
+ registerCouncilSigner(): Promise<TestTxResult>;
381
389
  forceSingleMemberCouncil(): Promise<{
382
390
  activeCouncilHash: `0x${string}`;
383
391
  activeCouncil: _argonprotocol_mainchain.PalletCrosschainTransferGlobalIssuanceCouncil;
@@ -386,7 +394,7 @@ declare class TestMintingAuthorityActor {
386
394
  weights: bigint[];
387
395
  };
388
396
  }>;
389
- registerMintingAuthority(micronotCollateral: bigint): Promise<_argonprotocol_mainchain.TxResult>;
397
+ registerMintingAuthority(micronotCollateral: bigint): Promise<TestTxResult>;
390
398
  approveActivationQueueEntry(queueNonce?: bigint): Promise<{
391
399
  approvalQueueEntry: _polkadot_types_codec.Option<_argonprotocol_mainchain.PalletCrosschainTransferCouncilApprovalQueueEntry>;
392
400
  councilApprovalSignature: `0x${string}`;
@@ -408,7 +416,7 @@ declare class TestMintingAuthorityActor {
408
416
  };
409
417
  micronotCollateral: bigint;
410
418
  collateralizationSignature: `0x${string}`;
411
- result: _argonprotocol_mainchain.TxResult;
419
+ result: TestTxResult;
412
420
  }>;
413
421
  private registrationMessage;
414
422
  private requireGateway;
@@ -418,4 +426,4 @@ declare function stringifyExt(obj: any): any;
418
426
  declare function sudo(): KeyringPair;
419
427
  declare function activateNotary(sudo: KeyringPair, client: ArgonClient, notary: TestNotary): Promise<void>;
420
428
 
421
- export { type EthereumGatewayUpdateBatch, EthereumProofE2eHarness, type ITeardownable, SKIP_E2E, TestEthereum, TestMainchain, TestMintingAuthorityActor, TestMintingGateway, TestNotary, TestOracle, activateNotary, addTeardown, cleanHostForDocker, closeOnTeardown, disconnectOnTeardown, getDockerPortMapping, getProxy, getReadyEthereumGatewayUpdates, mineLaterExecutionAnchorReceipt, projectRoot, runOnTeardown, runTestScript, signGatewayPermit, startNetwork, stringifyExt, sudo, syncEthereumVerifierUntilAnchorCovers, teardown, toArgonKeccakSignature, toEvmRecoverableSignature, waitForExecutionReceipt, waitForFinalizedBeaconExecutionAtOrAbove };
429
+ export { type EthereumGatewayUpdateBatch, EthereumProofE2eHarness, type ITeardownable, SKIP_E2E, TestEthereum, TestMainchain, TestMintingAuthorityActor, TestMintingGateway, TestNotary, TestOracle, type TestTxResult, activateNotary, addTeardown, cleanHostForDocker, closeOnTeardown, disconnectOnTeardown, getDockerPortMapping, getProxy, getReadyEthereumGatewayUpdates, mineLaterExecutionAnchorReceipt, projectRoot, runOnTeardown, runTestScript, signGatewayPermit, startNetwork, stringifyExt, submitTx, sudo, syncEthereumVerifierUntilAnchorCovers, teardown, toArgonKeccakSignature, toEvmRecoverableSignature, waitForExecutionReceipt, waitForFinalizedBeaconExecutionAtOrAbove };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _argonprotocol_mainchain from '@argonprotocol/mainchain';
2
- import { KeyringPair, ArgonClient, EthereumReceipt, EthereumBeaconHeaderDetailsResponse, EthereumBeaconBlockResponse, EvmContracts, IArgonQueryable } from '@argonprotocol/mainchain';
2
+ import { KeyringPair, ArgonClient, GenericEvent, SubmittableExtrinsic, EthereumReceipt, EthereumBeaconHeaderDetailsResponse, EthereumBeaconBlockResponse, EvmContracts, IArgonQueryable } from '@argonprotocol/mainchain';
3
3
  import { Client } from 'pg';
4
4
  import * as viem from 'viem';
5
5
  import { Hex, createWalletClient, defineChain, Address, ContractFunctionArgs } from 'viem';
@@ -189,6 +189,14 @@ declare function startNetwork(testName: string, options?: {
189
189
  notaryUrl: string;
190
190
  }>;
191
191
 
192
+ type TestTxResult = {
193
+ blockHash: string;
194
+ events: GenericEvent[];
195
+ finalFee?: bigint;
196
+ };
197
+ /** Sign a test transaction and resolve once it is included successfully in a block. */
198
+ declare function submitTx(client: ArgonClient, tx: SubmittableExtrinsic, signer: KeyringPair): Promise<TestTxResult>;
199
+
192
200
  declare function signGatewayPermit(args: {
193
201
  account: ReturnType<typeof privateKeyToAccount>;
194
202
  chainId: number;
@@ -291,20 +299,20 @@ declare class EthereumProofE2eHarness {
291
299
  };
292
300
  proofRelayerUri: string;
293
301
  }): Promise<EthereumProofE2eHarness>;
294
- submit(tx: unknown, signer: KeyringPair): Promise<_argonprotocol_mainchain.TxResult>;
295
- sudoSubmit(tx: unknown): Promise<_argonprotocol_mainchain.TxResult>;
302
+ submit(tx: SubmittableExtrinsic, signer: KeyringPair): Promise<TestTxResult>;
303
+ sudoSubmit(tx: SubmittableExtrinsic): Promise<TestTxResult>;
296
304
  syncVerifierThrough(minimumExecutionBlockNumber: bigint): Promise<void>;
297
305
  proveGatewayActivity(gatewayAddress: Hex, throughExecutionBlockNumber: bigint): Promise<{
298
306
  payload: _argonprotocol_mainchain.EthereumGatewayActivityProofPayload;
299
- result: _argonprotocol_mainchain.TxResult;
307
+ result: TestTxResult;
300
308
  }>;
301
309
  configureEthereumRuntime(gateway: TestMintingGateway, mode: RuntimeSetupMode): Promise<{
302
- result: _argonprotocol_mainchain.TxResult;
310
+ result: TestTxResult;
303
311
  }>;
304
- fundBurnAccount(amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
305
- fundProofRelayer(amount?: bigint): Promise<_argonprotocol_mainchain.TxResult>;
306
- forceSetBalance(address: string, amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
307
- forceSetOwnership(address: string, amount: bigint): Promise<_argonprotocol_mainchain.TxResult>;
312
+ fundBurnAccount(amount: bigint): Promise<TestTxResult>;
313
+ fundProofRelayer(amount?: bigint): Promise<TestTxResult>;
314
+ forceSetBalance(address: string, amount: bigint): Promise<TestTxResult>;
315
+ forceSetOwnership(address: string, amount: bigint): Promise<TestTxResult>;
308
316
  waitForExecutionFinalizedAfter(minimumExecutionBlockNumber: bigint): Promise<viem.TransactionReceipt>;
309
317
  }
310
318
  declare class TestMintingGateway {
@@ -375,9 +383,9 @@ declare class TestMintingAuthorityActor {
375
383
  freeBalance: bigint;
376
384
  ownershipBalance: bigint;
377
385
  committedArgonots: bigint;
378
- bitcoinXpub: string;
386
+ bitcoinXpubBytesHex: string;
379
387
  }): Promise<void>;
380
- registerCouncilSigner(): Promise<_argonprotocol_mainchain.TxResult>;
388
+ registerCouncilSigner(): Promise<TestTxResult>;
381
389
  forceSingleMemberCouncil(): Promise<{
382
390
  activeCouncilHash: `0x${string}`;
383
391
  activeCouncil: _argonprotocol_mainchain.PalletCrosschainTransferGlobalIssuanceCouncil;
@@ -386,7 +394,7 @@ declare class TestMintingAuthorityActor {
386
394
  weights: bigint[];
387
395
  };
388
396
  }>;
389
- registerMintingAuthority(micronotCollateral: bigint): Promise<_argonprotocol_mainchain.TxResult>;
397
+ registerMintingAuthority(micronotCollateral: bigint): Promise<TestTxResult>;
390
398
  approveActivationQueueEntry(queueNonce?: bigint): Promise<{
391
399
  approvalQueueEntry: _polkadot_types_codec.Option<_argonprotocol_mainchain.PalletCrosschainTransferCouncilApprovalQueueEntry>;
392
400
  councilApprovalSignature: `0x${string}`;
@@ -408,7 +416,7 @@ declare class TestMintingAuthorityActor {
408
416
  };
409
417
  micronotCollateral: bigint;
410
418
  collateralizationSignature: `0x${string}`;
411
- result: _argonprotocol_mainchain.TxResult;
419
+ result: TestTxResult;
412
420
  }>;
413
421
  private registrationMessage;
414
422
  private requireGateway;
@@ -418,4 +426,4 @@ declare function stringifyExt(obj: any): any;
418
426
  declare function sudo(): KeyringPair;
419
427
  declare function activateNotary(sudo: KeyringPair, client: ArgonClient, notary: TestNotary): Promise<void>;
420
428
 
421
- export { type EthereumGatewayUpdateBatch, EthereumProofE2eHarness, type ITeardownable, SKIP_E2E, TestEthereum, TestMainchain, TestMintingAuthorityActor, TestMintingGateway, TestNotary, TestOracle, activateNotary, addTeardown, cleanHostForDocker, closeOnTeardown, disconnectOnTeardown, getDockerPortMapping, getProxy, getReadyEthereumGatewayUpdates, mineLaterExecutionAnchorReceipt, projectRoot, runOnTeardown, runTestScript, signGatewayPermit, startNetwork, stringifyExt, sudo, syncEthereumVerifierUntilAnchorCovers, teardown, toArgonKeccakSignature, toEvmRecoverableSignature, waitForExecutionReceipt, waitForFinalizedBeaconExecutionAtOrAbove };
429
+ export { type EthereumGatewayUpdateBatch, EthereumProofE2eHarness, type ITeardownable, SKIP_E2E, TestEthereum, TestMainchain, TestMintingAuthorityActor, TestMintingGateway, TestNotary, TestOracle, type TestTxResult, activateNotary, addTeardown, cleanHostForDocker, closeOnTeardown, disconnectOnTeardown, getDockerPortMapping, getProxy, getReadyEthereumGatewayUpdates, mineLaterExecutionAnchorReceipt, projectRoot, runOnTeardown, runTestScript, signGatewayPermit, startNetwork, stringifyExt, submitTx, sudo, syncEthereumVerifierUntilAnchorCovers, teardown, toArgonKeccakSignature, toEvmRecoverableSignature, waitForExecutionReceipt, waitForFinalizedBeaconExecutionAtOrAbove };
package/lib/index.js CHANGED
@@ -6,13 +6,13 @@ var getDirname = () => path.dirname(getFilename());
6
6
  var __dirname = /* @__PURE__ */ getDirname();
7
7
 
8
8
  // src/index.ts
9
- import { Keyring as Keyring4, TxSubmitter as TxSubmitter4 } from "@argonprotocol/mainchain";
9
+ import { Keyring as Keyring4 } from "@argonprotocol/mainchain";
10
10
 
11
11
  // src/TestNotary.ts
12
12
  import { customAlphabet } from "nanoid";
13
13
  import pg from "pg";
14
14
  import * as child_process2 from "child_process";
15
- import { Keyring, TxSubmitter } from "@argonprotocol/mainchain";
15
+ import { Keyring } from "@argonprotocol/mainchain";
16
16
  import * as fs from "fs";
17
17
  import * as readline from "readline";
18
18
 
@@ -114,6 +114,50 @@ function disconnectOnTeardown(closeable) {
114
114
  // src/TestNotary.ts
115
115
  import * as process3 from "process";
116
116
  import * as Path2 from "path";
117
+
118
+ // src/submitTx.ts
119
+ import {
120
+ checkForExtrinsicSuccess
121
+ } from "@argonprotocol/mainchain";
122
+ function submitTx(client, tx, signer) {
123
+ return new Promise((resolve3, reject) => {
124
+ let unsubscribe;
125
+ let completed = false;
126
+ const finish = (callback) => {
127
+ completed = true;
128
+ unsubscribe?.();
129
+ callback();
130
+ };
131
+ tx.signAndSend(signer, (result) => {
132
+ if (completed) return;
133
+ if (result.status.isDropped || result.status.isInvalid || result.status.isUsurped) {
134
+ finish(() => reject(new Error(`Transaction ${result.status.type.toLowerCase()}`)));
135
+ return;
136
+ }
137
+ if (!result.status.isInBlock) return;
138
+ void checkForExtrinsicSuccess(result.events, client).then(
139
+ () => {
140
+ const feePaid = result.events.find(
141
+ ({ event }) => client.events.transactionPayment.TransactionFeePaid.is(event)
142
+ );
143
+ finish(
144
+ () => resolve3({
145
+ blockHash: result.status.asInBlock.toHex(),
146
+ events: result.events.map(({ event }) => event),
147
+ finalFee: feePaid && client.events.transactionPayment.TransactionFeePaid.is(feePaid.event) ? feePaid.event.data.actualFee.toBigInt() : void 0
148
+ })
149
+ );
150
+ },
151
+ (error) => finish(() => reject(error))
152
+ );
153
+ }).then((stop) => {
154
+ unsubscribe = stop;
155
+ if (completed) unsubscribe();
156
+ }).catch((error) => finish(() => reject(error)));
157
+ });
158
+ }
159
+
160
+ // src/TestNotary.ts
117
161
  var { Client: PgClient } = pg;
118
162
  var nanoid = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 4);
119
163
  function createUid() {
@@ -246,7 +290,7 @@ var TestNotary = class {
246
290
  }
247
291
  async register(client) {
248
292
  const address = new URL(this.address);
249
- const result = await new TxSubmitter(
293
+ await submitTx(
250
294
  client,
251
295
  client.tx.notaries.propose({
252
296
  public: this.registeredPublicKey,
@@ -254,8 +298,7 @@ var TestNotary = class {
254
298
  name: "Test Notary"
255
299
  }),
256
300
  this.operator
257
- ).submit();
258
- await result.waitForInFirstBlock;
301
+ );
259
302
  }
260
303
  async teardown() {
261
304
  this.#childProcess?.kill();
@@ -1128,7 +1171,6 @@ import {
1128
1171
  getNextEthereumBeaconSyncTxs,
1129
1172
  hexToU8a,
1130
1173
  isOutdatedTransactionError,
1131
- TxSubmitter as TxSubmitter2,
1132
1174
  u8aToHex
1133
1175
  } from "@argonprotocol/mainchain";
1134
1176
  import { parseSignature } from "viem";
@@ -1263,8 +1305,7 @@ async function syncEthereumVerifierUntilAnchorCovers(mainchainClient, relayer, b
1263
1305
  let shouldRetry = false;
1264
1306
  for (const tx of txs) {
1265
1307
  try {
1266
- const result = await new TxSubmitter2(mainchainClient, tx, relayer).submit();
1267
- await result.waitForInFirstBlock;
1308
+ await submitTx(mainchainClient, tx, relayer);
1268
1309
  lastRetryableError = void 0;
1269
1310
  } catch (error) {
1270
1311
  if (isRetryableEthereumVerifierSyncError(error)) {
@@ -1605,12 +1646,13 @@ import {
1605
1646
  decodeAddress,
1606
1647
  dispatchErrorToString,
1607
1648
  EvmContracts as EvmContracts3,
1649
+ FIXED_U128_DECIMALS,
1608
1650
  getEthereumBeaconSyncBootstrapTx,
1651
+ hexToU8a as hexToU8a2,
1609
1652
  Keyring as Keyring3,
1653
+ PERMILL_DECIMALS,
1610
1654
  toFixedNumber,
1611
- TxSubmitter as TxSubmitter3,
1612
1655
  U8aFixed,
1613
- Vault,
1614
1656
  Vec
1615
1657
  } from "@argonprotocol/mainchain";
1616
1658
  import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
@@ -1688,15 +1730,10 @@ var EthereumProofE2eHarness = class _EthereumProofE2eHarness {
1688
1730
  );
1689
1731
  }
1690
1732
  async submit(tx, signer) {
1691
- const result = await new TxSubmitter3(this.mainchainClient, tx, signer).submit();
1692
- await result.waitForInFirstBlock;
1693
- return result;
1733
+ return submitTx(this.mainchainClient, tx, signer);
1694
1734
  }
1695
1735
  async sudoSubmit(tx) {
1696
- const result = await this.submit(
1697
- this.mainchainClient.tx.sudo.sudo(tx),
1698
- this.sudoSigner
1699
- );
1736
+ const result = await this.submit(this.mainchainClient.tx.sudo.sudo(tx.method), this.sudoSigner);
1700
1737
  const sudoEvent = result.events.find((event) => this.mainchainClient.events.sudo.Sudid.is(event));
1701
1738
  if (!sudoEvent || !this.mainchainClient.events.sudo.Sudid.is(sudoEvent)) {
1702
1739
  throw new Error("sudo did not emit sudo.Sudid");
@@ -1992,15 +2029,21 @@ var TestMintingAuthorityActor = class {
1992
2029
  async prepareOperator(args) {
1993
2030
  await this.harness.forceSetBalance(this.operator.address, args.freeBalance);
1994
2031
  await this.harness.forceSetOwnership(this.operator.address, args.ownershipBalance);
1995
- const vault = await Vault.create(this.harness.mainchainClient, this.operator, {
1996
- securitization: 1000000000n,
1997
- securitizationRatio: 1,
1998
- annualPercentRate: 0.05,
1999
- baseFee: 0n,
2000
- bitcoinXpub: args.bitcoinXpub,
2001
- treasuryProfitSharing: 0
2002
- });
2003
- await vault.getVault();
2032
+ await this.harness.submit(
2033
+ this.harness.mainchainClient.tx.vaults.create({
2034
+ terms: {
2035
+ bitcoinAnnualPercentRate: toFixedNumber(0.05, FIXED_U128_DECIMALS),
2036
+ bitcoinBaseFee: 0n,
2037
+ treasuryProfitSharing: toFixedNumber(0, PERMILL_DECIMALS),
2038
+ treasuryBonusProfitSharing: toFixedNumber(0, PERMILL_DECIMALS)
2039
+ },
2040
+ securitizationRatio: toFixedNumber(1, FIXED_U128_DECIMALS),
2041
+ securitization: 1000000000n,
2042
+ bitcoinXpubkey: hexToU8a2(args.bitcoinXpubBytesHex),
2043
+ delegateAccountId: null
2044
+ }),
2045
+ this.operator
2046
+ );
2004
2047
  await this.harness.sudoSubmit(
2005
2048
  this.harness.mainchainClient.tx.priceIndex.setOperator(this.operator.address)
2006
2049
  );
@@ -2229,12 +2272,11 @@ function sudo() {
2229
2272
  }
2230
2273
  async function activateNotary(sudo2, client, notary) {
2231
2274
  await notary.register(client);
2232
- const txResult = await new TxSubmitter4(
2275
+ await submitTx(
2233
2276
  client,
2234
2277
  client.tx.sudo.sudo(client.tx.notaries.activate(notary.operator.publicKey)),
2235
2278
  sudo2
2236
- ).submit();
2237
- await txResult.waitForInFirstBlock;
2279
+ );
2238
2280
  }
2239
2281
  export {
2240
2282
  EthereumProofE2eHarness,
@@ -2260,6 +2302,7 @@ export {
2260
2302
  signGatewayPermit,
2261
2303
  startNetwork,
2262
2304
  stringifyExt,
2305
+ submitTx,
2263
2306
  sudo,
2264
2307
  syncEthereumVerifierUntilAnchorCovers,
2265
2308
  teardown,