|
1 |
| -import { SmartContract, Token } from "../../src/evm"; |
| 1 | +import { SmartContract, Token, joinABIs } from "../../src/evm"; |
2 | 2 | import { sdk, signers } from "./before-setup";
|
3 | 3 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
4 | 4 | import { TokenERC20__factory } from "@thirdweb-dev/contracts-js";
|
5 | 5 | import { getContract, getContractFromAbi } from "../../src";
|
6 | 6 | import { expect } from "chai";
|
| 7 | +import { unique } from "../../src/evm/common/utils"; |
7 | 8 |
|
8 | 9 | describe("Functions", async () => {
|
9 | 10 | let adminWallet: SignerWithAddress;
|
@@ -52,4 +53,45 @@ describe("Functions", async () => {
|
52 | 53 | const balance = await contract.erc20.balance();
|
53 | 54 | expect(balance.displayValue).to.equal("0.0");
|
54 | 55 | });
|
| 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 | + }); |
55 | 97 | });
|
0 commit comments