From 1537d9b56ba0c3b54d4391d30a38ac9a5b9127ae Mon Sep 17 00:00:00 2001 From: Robert Leonard Date: Mon, 12 Feb 2024 20:12:59 -0500 Subject: [PATCH] Add test for gatekeeper service class --- .../integration/gatewayGatekeeper.test.ts | 79 +++++++++++++++---- .../test/integration/gatewayStaking.test.ts | 4 +- gateway-eth-ts/test/utils.ts | 1 + 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/gateway-eth-ts/test/integration/gatewayGatekeeper.test.ts b/gateway-eth-ts/test/integration/gatewayGatekeeper.test.ts index 259f17c9..599e74e2 100644 --- a/gateway-eth-ts/test/integration/gatewayGatekeeper.test.ts +++ b/gateway-eth-ts/test/integration/gatewayGatekeeper.test.ts @@ -1,32 +1,83 @@ import * as dotenv from "dotenv"; +import * as assert from "assert"; +import { GatewayGatekeeper } from "../../src/service/GatewayGatekeeper"; +import { GatewayNetwork__factory, GatewayNetwork } from "../../src/contracts/typechain-types"; +import { BaseProvider } from "@ethersproject/providers"; +import { Wallet, ethers, utils } from "ethers"; +import { BNB_TESTNET_CONTRACT_ADDRESSES, ZERO_ADDRESS, gatekeeperOneTestnetWallet, loadRelayerSigner } from "../utils"; dotenv.config(); -describe("Gateway Gatekeeper TS class", function () { +describe.only("Gateway Gatekeeper TS class", function () { + let gatekeeperClient: GatewayGatekeeper; + let gatewayNetworkContract: GatewayNetwork; - before("Initialize gateway gatekeeper ts class", async function () { + let provider: BaseProvider; + let gatekeeper: Wallet; + + const testNetworkName = utils.formatBytes32String("testNetworkClient"); + + before("Initialize gateway gatekeeper ts class", async function () { + this.timeout(20000); + provider = new ethers.providers.JsonRpcProvider("http://localhost:8545"); + + gatekeeper = gatekeeperOneTestnetWallet.connect(provider); + const singner = await loadRelayerSigner(); + + gatekeeperClient = new GatewayGatekeeper(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.gatekeeper); + gatewayNetworkContract = GatewayNetwork__factory.connect(BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork, singner); + + // Create a new test network + const primaryAuthorityAddress = await singner.getAddress(); + + + const networkCreateTx = await gatewayNetworkContract.connect(singner).createNetwork({ + primaryAuthority: primaryAuthorityAddress, + name: testNetworkName, + passExpireDurationInSeconds: 0, + networkFeatureMask: 0, + networkFee: { + issueFee: 0, + refreshFee: 0, + expireFee: 0, + freezeFee: 0 + }, + supportedToken: ZERO_ADDRESS, + gatekeepers: [], + lastFeeUpdateTimestamp: 0 + },{gasLimit: 300000}); + + await networkCreateTx.wait(); + // Add a new gatekeeper + + const addNewGatekeeperTx = await gatewayNetworkContract.connect(singner).addGatekeeper(gatekeeper.address, testNetworkName, {gasLimit: 300000}); + await addNewGatekeeperTx.wait(); + }); - it("should return the state of a valid gatekeeper", async function () { - // 1) Config - /** - * - Create a network - * - Add a gatekeeper - * - Read the gatekeepers data and verify - */ + it.skip("should return the state of a valid gatekeeper", async function () { + const gatekeeperState = await gatekeeperClient.getGatekeeperNetworkData(testNetworkName, gatekeeper.address); + + assert.equal(gatekeeperState.status, 1); + assert.equal(gatekeeperState.initialized, true); }); it("should fail to return the state of a gatekeeper that doesnt exist", async function () { - // 1) Config - /** - * - Try to read a gatekeeper that doesn't exist - */ + assert.throws(() => gatekeeperClient.getGatekeeperNetworkData(testNetworkName,gatekeeper.address), Error, "GatekeeperNotInNetwork"); }); it("should allow a gatekeeper to update their fee configuration", async function () { - + const resultTx = await gatekeeperClient.updateFeeConfig({ + issueFee: 20, + refreshFee: 0, + freezeFee: 10, + expireFee: 0 + }, + testNetworkName); + + await resultTx.wait(); }); it("should not allow a address that is not a gatekeeper to update their fee configuration", async function () { diff --git a/gateway-eth-ts/test/integration/gatewayStaking.test.ts b/gateway-eth-ts/test/integration/gatewayStaking.test.ts index 3e86844c..442254c9 100644 --- a/gateway-eth-ts/test/integration/gatewayStaking.test.ts +++ b/gateway-eth-ts/test/integration/gatewayStaking.test.ts @@ -1,7 +1,7 @@ import * as dotenv from "dotenv"; import { GatewayStaking } from "../../src/service/GatewayStaking"; -import { BaseProvider, TransactionReceipt, getDefaultProvider } from "@ethersproject/providers"; -import { PopulatedTransaction, Wallet, ethers } from "ethers"; +import { BaseProvider } from "@ethersproject/providers"; +import { Wallet, ethers } from "ethers"; import * as assert from "assert"; import { gatekeeperOneTestnetWallet, BNB_TESTNET_CONTRACT_ADDRESSES, loadRelayerSigner } from "../utils"; import { DummyBrokenERC20, DummyBrokenERC20__factory, GatewayStaking as GatewayStakingContract, GatewayStaking__factory } from "../../src/contracts/typechain-types"; diff --git a/gateway-eth-ts/test/utils.ts b/gateway-eth-ts/test/utils.ts index 7a642c66..6b4e19e8 100644 --- a/gateway-eth-ts/test/utils.ts +++ b/gateway-eth-ts/test/utils.ts @@ -7,6 +7,7 @@ export const DEFAULT_MNEMONIC = export const deployerWallet = new Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"); export const gatekeeperOneTestnetWallet = new Wallet("0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"); +export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; interface GatewayProtocolContractAddresses { flagsStorage: string,