Skip to content

Commit ca66827

Browse files
committed
unit test for unique filter
1 parent b967528 commit ca66827

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

packages/sdk/test/evm/functions.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { SmartContract, Token } from "../../src/evm";
1+
import { SmartContract, Token, joinABIs } from "../../src/evm";
22
import { sdk, signers } from "./before-setup";
33
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
44
import { TokenERC20__factory } from "@thirdweb-dev/contracts-js";
55
import { getContract, getContractFromAbi } from "../../src";
66
import { expect } from "chai";
7+
import { unique } from "../../src/evm/common/utils";
78

89
describe("Functions", async () => {
910
let adminWallet: SignerWithAddress;
@@ -52,4 +53,45 @@ describe("Functions", async () => {
5253
const balance = await contract.erc20.balance();
5354
expect(balance.displayValue).to.equal("0.0");
5455
});
56+
57+
it("check abi merge", async () => {
58+
const abi = TokenERC20__factory.abi;
59+
const joined = joinABIs([abi, abi, abi], abi);
60+
61+
expect(joined.length).to.equal(abi.length);
62+
63+
abi.forEach((n) => {
64+
const index = joined.findIndex((m) => {
65+
if (n.name) {
66+
return (
67+
n.name === m.name &&
68+
n.type === m.type &&
69+
n.inputs.length === m.inputs.length
70+
);
71+
} else {
72+
return n.type === m.type && n.inputs.length === m.inputs.length;
73+
}
74+
});
75+
76+
expect(index).to.be.greaterThanOrEqual(0);
77+
});
78+
});
79+
80+
it("check unique filter", async () => {
81+
const arrayOne = [1, 2, 3, 4];
82+
const arrayTwo = [4, 3, 2, 1];
83+
const arrayThree = [1, 2, 3, 4];
84+
const arrayFour = [4, 2, 3, 1];
85+
86+
let merged: number[] = [];
87+
merged.push(...arrayOne, ...arrayTwo, ...arrayThree, ...arrayFour);
88+
89+
const filtered = unique(merged, (a, b): boolean => a === b);
90+
91+
expect(filtered.length).to.equal(arrayOne.length);
92+
93+
arrayOne.forEach((n) => {
94+
expect(filtered.includes(n)).to.be.true;
95+
});
96+
});
5597
});

0 commit comments

Comments
 (0)