Skip to content

Commit

Permalink
Add test for gatekeeper service class
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed Feb 13, 2024
1 parent cb12ca3 commit 1537d9b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
79 changes: 65 additions & 14 deletions gateway-eth-ts/test/integration/gatewayGatekeeper.test.ts
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions gateway-eth-ts/test/integration/gatewayStaking.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions gateway-eth-ts/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1537d9b

Please sign in to comment.