Skip to content

Commit

Permalink
[KAIABridge] Handled untouched branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunsooda committed May 24, 2024
1 parent c590459 commit dbeb6f5
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 23 deletions.
2 changes: 1 addition & 1 deletion contracts/.solcover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
skipFiles: ["libs", "testing"],
skipFiles: ["libs", "testing", "system_contracts/kaiabridge/ReentrancyGuardUpgradeable.sol"],
};
34 changes: 34 additions & 0 deletions contracts/contracts/testing/kaiabridge/EnumerableSetUint64.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 The klaytn Authors
// This file is part of the klaytn library.
//
// The klaytn library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The klaytn library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.24;

import "../../system_contracts/kaiabridge/EnumerableSetUint64.sol";

contract TestEnumSet {
EnumerableSet.UintSet s;

constructor() {}

function add(uint64 v) public {
EnumerableSetUint64.setAdd(s, v);
}

function at(uint64 idx) public view returns (uint64) {
return EnumerableSetUint64.setAt(s, idx);
}
}
45 changes: 33 additions & 12 deletions contracts/test/KAIABridge/addr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { expect } from "chai";

describe("", function () {
const validAddrs = [
"link1hpufl3l8g44aaz3qsqw886sjanhhu73ul6tllxuw3pqlhxzq9e4svku69h",
"link10pgvx8pn5qwgwv066g93jlqux6mnsp0kajg9hp",
];
const invalidAddrs = [
"link1hpufl3l8g44aaz3qsqw886sjanhhu63ul6tllxuw3pqlhxzq9e4svku69h",
"link10pgvx8pn5qwgwv066g93jlqux5mnsp0kajg9hp",
];
let bech32;

beforeEach(async function() {
Expand All @@ -9,23 +17,36 @@ describe("", function () {
})

it("FNSA address validation", async function () {
const validAddrs = [
"link1hpufl3l8g44aaz3qsqw886sjanhhu73ul6tllxuw3pqlhxzq9e4svku69h",
"link10pgvx8pn5qwgwv066g93jlqux6mnsp0kajg9hp",
];

const invalidAddrs = [
"link1hpufl3l8g44aaz3qsqw886sjanhhu63ul6tllxuw3pqlhxzq9e4svku69h",
"link10pgvx8pn5qwgwv066g93jlqux5mnsp0kajg9hp",
];

for (let validAddr of validAddrs) {
expect(await (bech32.verifyAddrFNSA(validAddr, false))).to.be.equal(true);
expect(await (bech32.verifyAddrFNSA(validAddr.toLowerCase(), true))).to.be.equal(true);
expect(await (bech32.verifyAddrFNSA(validAddr.toLowerCase(), false))).to.be.equal(true);
expect(await (bech32.verifyAddrFNSA(validAddr.toUpperCase(), true))).to.be.equal(true);
}

for (let invalidAddr of invalidAddrs) {
await expect(bech32.verifyAddrFNSA(invalidAddr, false))
await expect(bech32.verifyAddrFNSA(invalidAddr.toLowerCase(), true))
.to.be.revertedWith("Invalid checksum");
await expect(bech32.verifyAddrFNSA(invalidAddr.toLowerCase(), false))
.to.be.revertedWith("Invalid checksum");
await expect(bech32.verifyAddrFNSA(invalidAddr.toUpperCase(), true))
.to.be.revertedWith("Invalid checksum");
}

await expect(bech32.decodeNoLimit("0x1234", false))
.to.be.revertedWith("invalid bech32 string length")
})

it("Input validation", async function () {
await expect(bech32.normalize("0xAA"))
.to.be.revertedWith("Not allowed ASCII value");

await expect(bech32.normalize(Buffer.from("Link10pgvx8pn5qwgwv066g93jlqux6mnsp0kajg9hp")))
.to.be.revertedWith("string not all lowercase or all uppercase");

await expect(bech32.copyBytes("0xaa", 1, 0))
.to.be.revertedWith("from must be less than to");

await expect(bech32.copyBytes("0xaa", 0, 10))
.to.be.revertedWith("to must be less than or equal source length");
})
})
Loading

0 comments on commit dbeb6f5

Please sign in to comment.