Skip to content

Commit

Permalink
add remaining test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed Jun 25, 2024
1 parent ff2a218 commit 401a96e
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gatekeeper-cli/src/commands/claim-network-authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
}
}
4 changes: 2 additions & 2 deletions gatekeeper-cli/src/commands/transfer-network-authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
}
}
4 changes: 2 additions & 2 deletions gatekeeper-cli/src/test/integration/add-gatekeeper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
})
})
Original file line number Diff line number Diff line change
@@ -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")
})
})
Empty file.
67 changes: 67 additions & 0 deletions gatekeeper-cli/src/test/integration/remove-gatekeeper.spec.ts
Original file line number Diff line number Diff line change
@@ -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")
})
})
Empty file.
2 changes: 1 addition & 1 deletion gatekeeper-cli/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 401a96e

Please sign in to comment.