Skip to content

Commit

Permalink
Merge pull request #14 from VenusProtocol/feat/VEN-2271
Browse files Browse the repository at this point in the history
[VEN-2271]: add tests to increase coverage
  • Loading branch information
GitGuru7 authored Jan 9, 2024
2 parents 6cd953d + 1969bd5 commit 6a41991
Show file tree
Hide file tree
Showing 3 changed files with 772 additions and 30 deletions.
73 changes: 51 additions & 22 deletions test/bridgeAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ describe("Bridge Admin: ", function () {
const singleTransactionLimit = convertToUnit(10, 18);
const maxDailyTransactionLimit = convertToUnit(100, 18);

const functionregistry = [
"setOracle(address)",
"setMaxSingleTransactionLimit(uint16,uint256)",
"setMaxDailyLimit(uint16,uint256)",
"setMaxSingleReceiveTransactionLimit(uint16,uint256)",
"setMaxDailyReceiveLimit(uint16,uint256)",
"pause()",
"unpause()",
"setWhitelist(address,bool)",
"setConfig(uint16,uint16,uint256,bytes)",
"setSendVersion(uint16)",
"setReceiveVersion(uint16)",
"forceResumeReceive(uint16,bytes)",
"setTrustedRemoteAddress(uint16,bytes)",
"setPrecrime(address)",
"setMinDstGas(uint16,uint16,uint256)",
"setPayloadSizeLimit(uint16,uint256)",
"removeTrustedRemote(uint16)",
"updateSendAndCallEnabled(bool)",
"sweepToken(address,address,uint256)",
"dropFailedMessage(uint16,bytes,uint64)",
];

let LZEndpointMock: LZEndpointMock__factory,
ProxyOFTV2Dest: XVSProxyOFTDest__factory,
RemoteTokenFactory: XVS__factory,
Expand Down Expand Up @@ -84,39 +107,46 @@ describe("Bridge Admin: ", function () {
await remoteOFT.transferOwnership(bridgeAdmin.address);

remotePath = ethers.utils.solidityPack(["address", "address"], [AddressOne, remoteOFT.address]);
const functionregistry = [
"setOracle(address)",
"setMaxSingleTransactionLimit(uint16,uint256)",
"setMaxDailyLimit(uint16,uint256)",
"setMaxSingleReceiveTransactionLimit(uint16,uint256)",
"setMaxDailyReceiveLimit(uint16,uint256)",
"pause()",
"unpause()",
"setWhitelist(address,bool)",
"setConfig(uint16,uint16,uint256,bytes)",
"setSendVersion(uint16)",
"setReceiveVersion(uint16)",
"forceResumeReceive(uint16,bytes)",
"setTrustedRemote(uint16,bytes)",
"setTrustedRemoteAddress(uint16,bytes)",
"setPrecrime(address)",
"setMinDstGas(uint16,uint16,uint256)",
"setPayloadSizeLimit(uint16,uint256)",
"setUseCustomAdapterParams(bool)",
];

const activeArray = new Array(functionregistry.length).fill(true);
await bridgeAdmin.upsertSignature(functionregistry, activeArray);
await loadFixture(grantPermissionsFixture);
});

it("Revert when inputs length mismatch in function registry", async function () {
const activeArray = new Array(functionregistry.length - 1).fill(true);

await expect(bridgeAdmin.upsertSignature(functionregistry, activeArray)).to.be.revertedWith(
"Input arrays must have the same length",
);
});

it("Deletes from function registry", async function () {
const activeArray = new Array(functionregistry.length).fill(true);
await bridgeAdmin.upsertSignature(functionregistry, activeArray);
await bridgeAdmin.upsertSignature(["fakeFunction(uint256)"], [true]);
await expect(bridgeAdmin.upsertSignature(["fakeFunction(uint256)"], [false])).to.emit(
bridgeAdmin,
"FunctionRegistryChanged",
);
});

it("Reverts when non owner calls upsert signature", async function () {
const activeArray = new Array(functionregistry.length - 1).fill(true);

await expect(bridgeAdmin.connect(acc2).upsertSignature(functionregistry, activeArray)).to.be.revertedWith(
"Ownable: caller is not the owner",
);
});

it("Revert if EOA called owner function of bridge", async function () {
await expect(remoteOFT.connect(acc1).setTrustedRemote(localChainId, remotePath)).to.be.revertedWith(
"Ownable: caller is not the owner",
);
});

it("Revert if permissions are not granted to call owner functions of bridge", async function () {
let data = remoteOFT.interface.encodeFunctionData("setTrustedRemote", [localChainId, remotePath]);
let data = remoteOFT.interface.encodeFunctionData("setTrustedRemoteAddress", [localChainId, remotePath]);
await expect(
acc1.sendTransaction({
to: bridgeAdmin.address,
Expand Down Expand Up @@ -162,7 +192,6 @@ describe("Bridge Admin: ", function () {
}),
).to.revertedWithCustomError(bridgeAdmin, "Unauthorized");
});

it("Success if permissions are granted to call owner functions of bridge", async function () {
let data = remoteOFT.interface.encodeFunctionData("setMaxDailyLimit", [localChainId, maxDailyTransactionLimit]);
await acc2.sendTransaction({
Expand Down
Loading

0 comments on commit 6a41991

Please sign in to comment.