@argonprotocol/testing 1.4.6 → 1.4.7-dev.6244465b

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.cjs CHANGED
@@ -32,7 +32,6 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  EthereumProofE2eHarness: () => EthereumProofE2eHarness,
34
34
  SKIP_E2E: () => SKIP_E2E,
35
- TestBitcoinCli: () => TestBitcoinCli,
36
35
  TestEthereum: () => TestEthereum,
37
36
  TestMainchain: () => TestMainchain,
38
37
  TestMintingAuthorityActor: () => TestMintingAuthorityActor,
@@ -624,34 +623,13 @@ var BitcoinRpcClient = class {
624
623
  }
625
624
  };
626
625
 
627
- // src/TestBitcoinCli.ts
628
- var child_process3 = __toESM(require("child_process"), 1);
629
- var Path4 = __toESM(require("path"), 1);
630
- var TestBitcoinCli = class {
631
- /**
632
- * Returns the localhost address of the notary (NOTE: not accessible from containers)
633
- */
634
- static run(command) {
635
- const binPath = Path4.join(`${projectRoot()}`, "target/debug/argon-bitcoin-cli");
636
- try {
637
- return child_process3.execSync(`${binPath} ${command}`, {
638
- encoding: "utf8"
639
- }).trim();
640
- } catch (e) {
641
- console.error(`Error running command: ${command}`);
642
- console.error(e.stdout);
643
- throw e;
644
- }
645
- }
646
- };
647
-
648
626
  // src/TestOracle.ts
649
- var child_process4 = __toESM(require("child_process"), 1);
627
+ var child_process3 = __toESM(require("child_process"), 1);
650
628
  var import_mainchain3 = require("@argonprotocol/mainchain");
651
629
  var fs3 = __toESM(require("fs"), 1);
652
630
  var readline3 = __toESM(require("readline"), 1);
653
631
  var process4 = __toESM(require("process"), 1);
654
- var Path5 = __toESM(require("path"), 1);
632
+ var Path4 = __toESM(require("path"), 1);
655
633
  var TestOracle = class _TestOracle {
656
634
  static BitcoinOperator = "//Dave";
657
635
  static PriceIndexOperator = "//Eve";
@@ -666,7 +644,7 @@ var TestOracle = class _TestOracle {
666
644
  const { pathToBin, mainchainUrl, bitcoinRpcUrl } = options;
667
645
  const operatorSuri = service == "bitcoin" ? _TestOracle.BitcoinOperator : _TestOracle.PriceIndexOperator;
668
646
  this.operator = new import_mainchain3.Keyring({ type: "sr25519" }).createFromUri(operatorSuri);
669
- const binPath = pathToBin ?? Path5.join(projectRoot(), "target/debug/argon-oracle");
647
+ const binPath = pathToBin ?? Path4.join(projectRoot(), "target/debug/argon-oracle");
670
648
  if (!fs3.existsSync(binPath)) {
671
649
  throw new Error(`Oracle binary not found at ${binPath}`);
672
650
  }
@@ -678,7 +656,7 @@ var TestOracle = class _TestOracle {
678
656
  }
679
657
  execArgs.push("--bitcoin-rpc-url", bitcoinRpcUrl);
680
658
  }
681
- this.#childProcess = child_process4.spawn(binPath, execArgs, {
659
+ this.#childProcess = child_process3.spawn(binPath, execArgs, {
682
660
  stdio: ["ignore", "pipe", "pipe"],
683
661
  env: { ...process4.env, RUST_LOG: "info", ...options.env }
684
662
  });
@@ -703,7 +681,7 @@ var TestOracle = class _TestOracle {
703
681
  // src/TestEthereum.ts
704
682
  var fs4 = __toESM(require("fs/promises"), 1);
705
683
  var os = __toESM(require("os"), 1);
706
- var Path6 = __toESM(require("path"), 1);
684
+ var Path5 = __toESM(require("path"), 1);
707
685
  var import_node_child_process2 = require("child_process");
708
686
  var import_detect_port2 = require("detect-port");
709
687
  var import_mainchain4 = require("@argonprotocol/mainchain");
@@ -757,8 +735,8 @@ var TestEthereum = class {
757
735
  } = options ?? {};
758
736
  const elPublicPortStart = await findFreePortRange(DEFAULT_EL_PORT_START, PORT_RANGE_SIZE);
759
737
  const clPublicPortStart = await findFreePortRange(DEFAULT_CL_PORT_START, PORT_RANGE_SIZE);
760
- this.#argsDir = await fs4.mkdtemp(Path6.join(os.tmpdir(), "argon-ethereum-devnet-"));
761
- const argsFile = Path6.join(this.#argsDir, "network-params.yaml");
738
+ this.#argsDir = await fs4.mkdtemp(Path5.join(os.tmpdir(), "argon-ethereum-devnet-"));
739
+ const argsFile = Path5.join(this.#argsDir, "network-params.yaml");
762
740
  await fs4.writeFile(
763
741
  argsFile,
764
742
  renderEthereumArgs(
@@ -1158,9 +1136,9 @@ async function delay(ms) {
1158
1136
 
1159
1137
  // src/TestNetwork.ts
1160
1138
  var docker = __toESM(require("docker-compose"), 1);
1161
- var Path7 = __toESM(require("path"), 1);
1139
+ var Path6 = __toESM(require("path"), 1);
1162
1140
  async function startNetwork(testName, options) {
1163
- const config = Path7.join(__dirname, `dev.docker-compose.yml`);
1141
+ const config = Path6.join(__dirname, `dev.docker-compose.yml`);
1164
1142
  const env4 = {
1165
1143
  VERSION: "dev",
1166
1144
  ARGON_CHAIN: "dev-docker",
@@ -1382,7 +1360,6 @@ var {
1382
1360
  encodeMintingGatewayMintingAuthorityDeactivateTarget,
1383
1361
  hashMintingGatewayActivateMintingAuthority,
1384
1362
  hashMintingGatewayGatewayUpdateApproval,
1385
- hashMintingGatewayMintingAuthorityDeactivation,
1386
1363
  mintingGatewayAbi,
1387
1364
  MINTING_GATEWAY_UPDATE_KINDS
1388
1365
  } = import_mainchain6.EvmContracts;
@@ -1434,7 +1411,6 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1434
1411
  const argonApprovalsNonce = rawArgonApprovalsNonce;
1435
1412
  const argonApprovalsHash = rawArgonApprovalsHash;
1436
1413
  const paused = rawPaused;
1437
- const pendingClearOutQueueNonces = [];
1438
1414
  const candidateUpdates = [];
1439
1415
  let expectedPreviousApprovalHash = argonApprovalsHash;
1440
1416
  let readyQueueEntriesScanned = 0;
@@ -1449,14 +1425,8 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1449
1425
  }
1450
1426
  const entry = entryOption.unwrap();
1451
1427
  const approvingCouncilHash = toHexValue(entry.approvingCouncilHash);
1452
- if (!await queueEntryIsReady(
1453
- client,
1454
- entry,
1455
- approvingCouncilHash,
1456
- councilCache,
1457
- hashContext,
1458
- queueNonce
1459
- )) {
1428
+ const approvingCouncil = await loadCouncilByHash(client, approvingCouncilHash, councilCache);
1429
+ if (!queueEntryHasQuorum(entry, approvingCouncil)) {
1460
1430
  break;
1461
1431
  }
1462
1432
  readyQueueEntriesScanned += 1;
@@ -1473,10 +1443,15 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1473
1443
  expectedPreviousApprovalHash = toHexValue(entry.approvalHash);
1474
1444
  }
1475
1445
  }
1476
- while (candidateUpdates.length > 0 && candidateUpdates[candidateUpdates.length - 1]?.kind === MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate) {
1477
- pendingClearOutQueueNonces.unshift(candidateUpdates.pop().queueNonce);
1478
- }
1479
1446
  const updates = candidateUpdates;
1447
+ for (let index = 0; index < updates.length; index += 1) {
1448
+ const isBorder = updates[index].kind === MINTING_GATEWAY_UPDATE_KINDS.globalIssuanceCouncilRotate || index === updates.length - 1;
1449
+ if (isBorder || updates[index].signatures.length === 0) continue;
1450
+ updates[index] = {
1451
+ ...updates[index],
1452
+ signatures: []
1453
+ };
1454
+ }
1480
1455
  const firstQueueNonce = updates[0]?.queueNonce;
1481
1456
  const lastQueueNonce = updates[updates.length - 1]?.queueNonce;
1482
1457
  return {
@@ -1488,7 +1463,6 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1488
1463
  argonApprovalsNonce,
1489
1464
  argonApprovalsHash,
1490
1465
  paused,
1491
- pendingClearOutQueueNonces,
1492
1466
  ...firstQueueNonce !== void 0 ? { firstQueueNonce, lastQueueNonce } : {},
1493
1467
  updates
1494
1468
  };
@@ -1516,7 +1490,7 @@ async function buildGatewayUpdate(client, destinationChain, hashContext, queueNo
1516
1490
  signingKey
1517
1491
  };
1518
1492
  const payload = encodeMintingGatewayMintingAuthorityActivationTarget(target);
1519
- const targetPayloadHash = payloadHashFromActivationPayload(hashContext, target);
1493
+ const targetPayloadHash = hashMintingGatewayActivateMintingAuthority(hashContext, target);
1520
1494
  const approvalHash = hashMintingGatewayGatewayUpdateApproval(hashContext, {
1521
1495
  queueNonce,
1522
1496
  approvingCouncilHash,
@@ -1541,17 +1515,30 @@ async function buildGatewayUpdate(client, destinationChain, hashContext, queueNo
1541
1515
  };
1542
1516
  }
1543
1517
  if (entry.target.isMintingAuthorityDeactivation) {
1544
- const { payload, signatures } = validateDeactivationEntry(
1545
- hashContext,
1518
+ const signingKey = (0, import_viem3.getAddress)(toHexValue(entry.target.asMintingAuthorityDeactivation));
1519
+ const payload = encodeMintingGatewayMintingAuthorityDeactivateTarget({ signingKey });
1520
+ const targetPayloadHash = (0, import_viem3.keccak256)(payload);
1521
+ const approvalHash = hashMintingGatewayGatewayUpdateApproval(hashContext, {
1546
1522
  queueNonce,
1547
- entry,
1548
- approvingCouncilHash
1549
- );
1523
+ approvingCouncilHash,
1524
+ kind: MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate,
1525
+ targetId: signingKeyTargetId(signingKey),
1526
+ targetPayloadHash,
1527
+ previousUpdateHash: toHexValue(entry.previousApprovalHash)
1528
+ });
1529
+ if (toHexValue(entry.targetPayloadHash) !== targetPayloadHash) {
1530
+ throw new Error(`Queue nonce ${queueNonce} target payload hash does not match deactivation`);
1531
+ }
1532
+ if (toHexValue(entry.approvalHash) !== approvalHash) {
1533
+ throw new Error(
1534
+ `Queue nonce ${queueNonce} approval hash does not match deactivation: actual=${toHexValue(entry.approvalHash)} expected=${approvalHash} previous=${toHexValue(entry.previousApprovalHash)} council=${approvingCouncilHash}`
1535
+ );
1536
+ }
1550
1537
  return {
1551
1538
  queueNonce,
1552
1539
  kind: MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate,
1553
1540
  payload,
1554
- signatures
1541
+ signatures: getSortedSignatures(entry.signatures)
1555
1542
  };
1556
1543
  }
1557
1544
  throw new Error(`Unsupported approval queue target ${entry.target.type}`);
@@ -1577,23 +1564,20 @@ async function loadCouncilByHash(client, councilHash, cache) {
1577
1564
  return loaded;
1578
1565
  }
1579
1566
  function queueEntryHasQuorum(entry, council) {
1580
- const signedWeight = [...entry.signatures.entries()].reduce((total, [signer]) => {
1567
+ let signedWeight = 0n;
1568
+ for (const [signer] of entry.signatures.entries()) {
1581
1569
  const signerAddress = (0, import_viem3.getAddress)(toHexValue(signer));
1582
1570
  const member = council.members.find((x) => x.signer === signerAddress);
1583
1571
  if (!member) {
1584
1572
  throw new Error(`Signature submitted by ${signerAddress}, which is not in the council`);
1585
1573
  }
1586
- return total + member.weight;
1587
- }, 0n);
1588
- return signedWeight * 2n > council.totalWeight;
1589
- }
1590
- async function queueEntryIsReady(client, entry, approvingCouncilHash, councilCache, hashContext, queueNonce) {
1591
- if (entry.target.isMintingAuthorityDeactivation) {
1592
- validateDeactivationEntry(hashContext, queueNonce, entry, approvingCouncilHash);
1574
+ signedWeight += member.weight;
1575
+ }
1576
+ if (signedWeight * 100n >= council.totalWeight * 90n) {
1593
1577
  return true;
1594
1578
  }
1595
- const approvingCouncil = await loadCouncilByHash(client, approvingCouncilHash, councilCache);
1596
- return queueEntryHasQuorum(entry, approvingCouncil);
1579
+ const unsignedMemberCount = council.members.length - entry.signatures.size;
1580
+ return unsignedMemberCount <= 2 && signedWeight * 100n >= council.totalWeight * 80n;
1597
1581
  }
1598
1582
  function councilToSnapshot(council) {
1599
1583
  return {
@@ -1601,46 +1585,8 @@ function councilToSnapshot(council) {
1601
1585
  weights: council.members.map((member) => member.weight)
1602
1586
  };
1603
1587
  }
1604
- function payloadHashFromActivationPayload(hashContext, target) {
1605
- return hashMintingGatewayActivateMintingAuthority(hashContext, target);
1606
- }
1607
- function payloadHashFromDeactivationPayload(target) {
1608
- return (0, import_viem3.keccak256)(encodeMintingGatewayMintingAuthorityDeactivateTarget(target));
1609
- }
1610
- function validateDeactivationEntry(hashContext, queueNonce, entry, approvingCouncilHash) {
1611
- const signingKey = (0, import_viem3.getAddress)(toHexValue(entry.target.asMintingAuthorityDeactivation));
1612
- const target = { signingKey };
1613
- const payload = encodeMintingGatewayMintingAuthorityDeactivateTarget(target);
1614
- const targetPayloadHash = payloadHashFromDeactivationPayload(target);
1615
- const approvalHash = hashMintingGatewayMintingAuthorityDeactivation(hashContext, {
1616
- queueNonce,
1617
- target,
1618
- previousUpdateHash: toHexValue(entry.previousApprovalHash)
1619
- });
1620
- if (toHexValue(entry.targetPayloadHash) !== targetPayloadHash) {
1621
- throw new Error(`Queue nonce ${queueNonce} target payload hash does not match deactivation`);
1622
- }
1623
- if (toHexValue(entry.approvalHash) !== approvalHash) {
1624
- throw new Error(
1625
- `Queue nonce ${queueNonce} approval hash does not match deactivation: actual=${toHexValue(entry.approvalHash)} expected=${approvalHash} previous=${toHexValue(entry.previousApprovalHash)} council=${approvingCouncilHash}`
1626
- );
1627
- }
1628
- const deactivationSignatures = [...entry.signatures.entries()];
1629
- if (deactivationSignatures.length !== 1) {
1630
- throw new Error(
1631
- `Queue nonce ${queueNonce} expected exactly one deactivation signature, received ${deactivationSignatures.length}`
1632
- );
1633
- }
1634
- const [signer] = deactivationSignatures[0];
1635
- if ((0, import_viem3.getAddress)(toHexValue(signer)) !== signingKey) {
1636
- throw new Error(
1637
- `Queue nonce ${queueNonce} deactivation signature was submitted by ${(0, import_viem3.getAddress)(toHexValue(signer))}, expected ${signingKey}`
1638
- );
1639
- }
1640
- return {
1641
- payload,
1642
- signatures: getSortedSignatures(entry.signatures)
1643
- };
1588
+ function signingKeyTargetId(signingKey) {
1589
+ return `0x${signingKey.slice(2).padStart(64, "0").toLowerCase()}`;
1644
1590
  }
1645
1591
  function getSortedSignatures(signatures) {
1646
1592
  return [...signatures.entries()].sort(
@@ -2270,7 +2216,6 @@ async function activateNotary(sudo2, client, notary) {
2270
2216
  0 && (module.exports = {
2271
2217
  EthereumProofE2eHarness,
2272
2218
  SKIP_E2E,
2273
- TestBitcoinCli,
2274
2219
  TestEthereum,
2275
2220
  TestMainchain,
2276
2221
  TestMintingAuthorityActor,