Skip to content

Commit

Permalink
improve test coverage for mainnet-wallet module
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Sep 11, 2024
1 parent 6d5c103 commit b3f89f0
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/modules/MainnetWalletModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,91 @@ describe("Faucet module: mainnet-wallet", () => {
expect(error?.getCode()).to.equal("MAINNET_BALANCE_LIMIT", "unexpected error code");
});

it("Start session with RPC issue during balance check", async () => {
faucetConfig.modules["mainnet-wallet"] = {
enabled: true,
rpcHost: fakeProvider,
minTxCount: 0,
minBalance: 1000,
} as IMainnetWalletConfig;
fakeProvider.injectResponse("eth_getBalance", (payload) => {
throw new Error("RPC error");
});
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let error: FaucetError | null = null;
try {
await sessionManager.createSession("::ffff:8.8.8.8", {
addr: "0x0000000000000000000000000000000000001337",
});
} catch(ex) {
error = ex;
}
expect(error).to.not.equal(null, "no exception thrown");
expect(error instanceof FaucetError).to.equal(true, "unexpected error type");
expect(error?.getCode()).to.equal("MAINNET_BALANCE_CHECK", "unexpected error code");
});

it("Start session with RPC issue during tx count check", async () => {
faucetConfig.modules["mainnet-wallet"] = {
enabled: true,
rpcHost: fakeProvider,
minTxCount: 10,
minBalance: 0,
} as IMainnetWalletConfig;
fakeProvider.injectResponse("eth_getTransactionCount", () => {
throw new Error("RPC error");
});
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let error: FaucetError | null = null;
try {
await sessionManager.createSession("::ffff:8.8.8.8", {
addr: "0x0000000000000000000000000000000000001337",
});
} catch(ex) {
error = ex;
}
expect(error).to.not.equal(null, "no exception thrown");
expect(error instanceof FaucetError).to.equal(true, "unexpected error type");
expect(error?.getCode()).to.equal("MAINNET_TXCOUNT_CHECK", "unexpected error code");
});

it("Start session with RPC issue during erc20 token balance check", async () => {
faucetConfig.modules["mainnet-wallet"] = {
enabled: true,
rpcHost: fakeProvider,
minTxCount: 0,
minErc20Balances: [
{
address: "0x0000000000000000000000000000000000000042",
name: "TestToken",
decimals: 12,
minBalance: 2000000000000, // 5 TestToken
}
],
} as IMainnetWalletConfig;
fakeProvider.injectResponse("eth_call", (payload) => {
switch(payload.params[0].data.substring(0, 10)) {
case "0x70a08231": // balanceOf()
throw new Error("RPC error");
default:
console.log("unknown call: ", payload);
}
});
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let error: FaucetError | null = null;
try {
await sessionManager.createSession("::ffff:8.8.8.8", {
addr: "0x0000000000000000000000000000000000001337",
});
} catch(ex) {
error = ex;
}
expect(error).to.not.equal(null, "no exception thrown");
expect(error instanceof FaucetError).to.equal(true, "unexpected error type");
expect(error?.getCode()).to.equal("MAINNET_BALANCE_CHECK", "unexpected error code");
});

});

0 comments on commit b3f89f0

Please sign in to comment.