From 401a96e360d3ffaabd7c5abc898bfe3ed41b3a2a Mon Sep 17 00:00:00 2001 From: Robert Leonard Date: Tue, 25 Jun 2024 17:11:37 -0400 Subject: [PATCH] add remaining test --- .../src/commands/claim-network-authority.ts | 2 +- .../commands/transfer-network-authority.ts | 4 +- .../test/integration/add-gatekeeper.spec.ts | 4 +- .../change-network-authority.spec.ts | 71 +++++++++++++++++++ .../claim-network-authority.spec.ts | 0 .../integration/remove-gatekeeper.spec.ts | 67 +++++++++++++++++ .../transfer-network-authority.spec.ts | 0 gatekeeper-cli/src/utils/index.ts | 2 +- 8 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 gatekeeper-cli/src/test/integration/change-network-authority.spec.ts delete mode 100644 gatekeeper-cli/src/test/integration/claim-network-authority.spec.ts delete mode 100644 gatekeeper-cli/src/test/integration/transfer-network-authority.spec.ts diff --git a/gatekeeper-cli/src/commands/claim-network-authority.ts b/gatekeeper-cli/src/commands/claim-network-authority.ts index d5af3e10..8825936c 100644 --- a/gatekeeper-cli/src/commands/claim-network-authority.ts +++ b/gatekeeper-cli/src/commands/claim-network-authority.ts @@ -58,7 +58,7 @@ export default class ClaimNetworkAuthority extends Command { const receipt = await sendableTransaction.wait(confirmations) this.log( - `Added network authority to Gateway Token contract. TxHash: ${receipt.transactionHash}`, + `Claim network authority to Gateway Token contract. TxHash: ${receipt.transactionHash}`, ) } } diff --git a/gatekeeper-cli/src/commands/transfer-network-authority.ts b/gatekeeper-cli/src/commands/transfer-network-authority.ts index eb227ba3..f5a35ca4 100644 --- a/gatekeeper-cli/src/commands/transfer-network-authority.ts +++ b/gatekeeper-cli/src/commands/transfer-network-authority.ts @@ -49,13 +49,13 @@ export default class TransferNetworkAuthority extends Command { authority ${authority} to network ${parsedFlags.gatekeeperNetwork}`) - const gatewayNetwork = await makeGatewayNetworkTs(parsedFlags) + const gatewayNetwork = await makeGatewayNetworkTs(parsedFlags) const sendableTransaction = await gatewayNetwork.updatePrimaryAuthority(networkName, authority); const receipt = await sendableTransaction.wait(confirmations) this.log( - `Added network authority to Gateway Token contract. TxHash: ${receipt.transactionHash}`, + `Transferring network authority to Gateway Token contract. TxHash: ${receipt.transactionHash}`, ) } } diff --git a/gatekeeper-cli/src/test/integration/add-gatekeeper.spec.ts b/gatekeeper-cli/src/test/integration/add-gatekeeper.spec.ts index 4290dfad..ab6d1066 100644 --- a/gatekeeper-cli/src/test/integration/add-gatekeeper.spec.ts +++ b/gatekeeper-cli/src/test/integration/add-gatekeeper.spec.ts @@ -8,7 +8,7 @@ import { GatewayNetworkClass } from "@identity.com/gateway-evm-ts-client/dist/se dotenv.config(); -describe("Command: Create network", function () { +describe("Command: Add gatekeeper to network", function () { let provider: BaseProvider; let testWallet: Wallet; let gatekeeper: Wallet; @@ -55,6 +55,6 @@ describe("Command: Create network", function () { const answer = await networkClient.isGatekeeper(utils.formatBytes32String(networkName), gatekeeper.address); - assert.equal(answer, true, "networkId should be non zero") + assert.equal(answer, true, "gatekeeper should be on network") }) }) \ No newline at end of file diff --git a/gatekeeper-cli/src/test/integration/change-network-authority.spec.ts b/gatekeeper-cli/src/test/integration/change-network-authority.spec.ts new file mode 100644 index 00000000..d6a71e2a --- /dev/null +++ b/gatekeeper-cli/src/test/integration/change-network-authority.spec.ts @@ -0,0 +1,71 @@ +import { BaseProvider } from "@ethersproject/providers"; +import * as dotenv from "dotenv"; +import { ethers, utils, Wallet } from "ethers"; +import {runCommand} from '@oclif/test' +import { BNB_TESTNET_CONTRACT_ADDRESSES, createRandomString, FOUNDRY_DEFAULT_WALLET_ONE, FOUNDRY_DEFAULT_WALLET_TWO, GatewayNetworkClient } from "../../utils"; +import assert = require('assert'); +import { GatewayNetworkClass } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayNetwork"; + +dotenv.config(); + +describe("Command: Transfer network authority", function () { + let provider: BaseProvider; + let testWallet: Wallet; + let newPrimaryAuthority: Wallet; + let networkClient: GatewayNetworkClass; + + before("Initialize wallet", async function () { + this.timeout(20000); + provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Test run against local node forked + + testWallet = FOUNDRY_DEFAULT_WALLET_ONE.connect(provider); + newPrimaryAuthority = FOUNDRY_DEFAULT_WALLET_TWO.connect(provider); + networkClient = GatewayNetworkClient(testWallet, BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork) + }); + + it("transfer network authority", async function () { + const networkName = createRandomString(4) + await runCommand([ + "create-gatekeeper-network", + networkName, + `${testWallet.address}`, + "a-test-network", + '0', + `0`, + `0x0000000000000000000000000000000000000000`, + `--privateKey=${testWallet.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + const result = await runCommand([ + "transfer-network-authority", + newPrimaryAuthority.address, + networkName, + `--privateKey=${testWallet.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + console.log(`output: ${result.stdout}`) + + assert.equal(result.error, undefined, "No errors should occur when creating network") + + const resultTwo = await runCommand([ + "claim-network-authority", + networkName, + `--privateKey=${newPrimaryAuthority.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + console.log(`output: ${result.stdout}`) + + assert.equal(resultTwo.error, undefined, "No errors should occur when creating network") + + const networkId = await networkClient.getNetworkId(networkName); + const answer = await networkClient.getNetwork(networkId.toString()); + + assert.equal(answer.primaryAuthority, newPrimaryAuthority.address, "networkId should be non zero") + }) +}) \ No newline at end of file diff --git a/gatekeeper-cli/src/test/integration/claim-network-authority.spec.ts b/gatekeeper-cli/src/test/integration/claim-network-authority.spec.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/gatekeeper-cli/src/test/integration/remove-gatekeeper.spec.ts b/gatekeeper-cli/src/test/integration/remove-gatekeeper.spec.ts index e69de29b..ae7cf809 100644 --- a/gatekeeper-cli/src/test/integration/remove-gatekeeper.spec.ts +++ b/gatekeeper-cli/src/test/integration/remove-gatekeeper.spec.ts @@ -0,0 +1,67 @@ +import { BaseProvider } from "@ethersproject/providers"; +import * as dotenv from "dotenv"; +import { ethers, utils, Wallet } from "ethers"; +import {runCommand} from '@oclif/test' +import { BNB_TESTNET_CONTRACT_ADDRESSES, createRandomString, FOUNDRY_DEFAULT_WALLET_ONE, GatewayNetworkClient } from "../../utils"; +import assert = require('assert'); +import { GatewayNetworkClass } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayNetwork"; + +dotenv.config(); + +describe("Command: Remove gatekeeper from network", function () { + let provider: BaseProvider; + let testWallet: Wallet; + let gatekeeper: Wallet; + let networkClient: GatewayNetworkClass; + + before("Initialize wallet", async function () { + this.timeout(20000); + provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Test run against local node forked + + testWallet = FOUNDRY_DEFAULT_WALLET_ONE.connect(provider); + gatekeeper = Wallet.createRandom(); + networkClient = GatewayNetworkClient(testWallet, BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork) + }); + + it("remove gatekeeper from network", async function () { + const networkName = createRandomString(8) + await runCommand([ + "create-gatekeeper-network", + networkName, + `${testWallet.address}`, + "a-test-network", + '0', + `0`, + `0x0000000000000000000000000000000000000000`, + `--privateKey=${testWallet.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + await runCommand([ + "add-gatekeeper", + gatekeeper.address, + networkName, + `--privateKey=${testWallet.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + const result = await runCommand([ + "remove-gatekeeper", + gatekeeper.address, + networkName, + `--privateKey=${testWallet.privateKey}`, + `--gatewayNetworkAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork}`, + `--chain=localhost` + ]) + + console.log(`output: ${result.stdout}`) + + assert.equal(result.error, undefined, "No errors should occur when creating network") + + const answer = await networkClient.isGatekeeper(utils.formatBytes32String(networkName), gatekeeper.address); + + assert.equal(answer, false, "gatekeeper should be removed") + }) +}) \ No newline at end of file diff --git a/gatekeeper-cli/src/test/integration/transfer-network-authority.spec.ts b/gatekeeper-cli/src/test/integration/transfer-network-authority.spec.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/gatekeeper-cli/src/utils/index.ts b/gatekeeper-cli/src/utils/index.ts index 8918c008..6acf1938 100644 --- a/gatekeeper-cli/src/utils/index.ts +++ b/gatekeeper-cli/src/utils/index.ts @@ -26,7 +26,7 @@ export const BNB_TESTNET_CONTRACT_ADDRESSES: GatewayProtocolContractAddresses = export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; export const FOUNDRY_DEFAULT_WALLET_ONE = new Wallet("0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d") // 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 - +export const FOUNDRY_DEFAULT_WALLET_TWO = new Wallet("0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"); // 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC /////// Gateway Protocol Helps ///// Smart contract clients