Skip to content

Commit

Permalink
add tests for getNamedTypes function
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Jul 12, 2023
1 parent 38e5144 commit 0ceb465
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
95 changes: 95 additions & 0 deletions modules/client-common/test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MetadataAbiInput } from "../src";

export const TEST_WALLET =
"0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e";
export const TEST_WALLET_ADDRESS = "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199";
Expand All @@ -13,3 +15,96 @@ export const web3endpoints = {
export const DEFAULT_IPFS_ENDPOINTS = [
"https://prod.ipfs.aragon.network/",
];

export const TEST_ABI: MetadataAbiInput[] = [
{
name: "a",
type: "tuple",
internalType: "struct A",
description: "A",
components: [
{
name: "b1",
type: "address",
internalType: "address",
description: "B1",
},
{
name: "b2",
type: "tuple",
internalType: "struct B2",
description: "B2",
components: [
{
name: "c1",
type: "uint256",
internalType: "uint256",
description: "C1",
},
{
name: "c2",
type: "tuple",
internalType: "struct C2",
description: "C2",
components: [
{
name: "d1",
type: "address",
internalType: "address",
description: "D1",
},
{
name: "d2",
type: "tuple",
internalType: "struct D2",
description: "D",
components: [
{
name: "e1",
type: "address[]",
internalType: "address[]",
description: "E1",
},
{
name: "e2",
type: "tuple",
internalType: "struct E2",
description: "E2",
components: [
{
name: "f1",
type: "uint32",
internalType: "uint32",
description: "F1",
},
{
name: "f2",
type: "tuple",
internalType: "struct F2",
description: "F2",
components: [
{
name: "g1",
type: "uint256",
internalType: "uint256",
description: "G1",
},
{
name: "g2",
type: "uint256",
internalType: "uint256",
description: "G2",
},
],
},
],
},
],
},
],
},
],
},
],
},
];
12 changes: 12 additions & 0 deletions modules/client-common/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getNamedTypesFromMetadata } from "../src";
import { TEST_ABI } from "./constants";
describe("Utils", () => {
describe("getNamedTypesFromMetadata", () => {
it("test abi with recursion and multiple types", () => {
const result = getNamedTypesFromMetadata(TEST_ABI);
expect(result).toEqual([
"tuple(address b1, tuple(uint256 c1, tuple(address d1, tuple(address[] e1, tuple(uint32 f1, tuple(uint256 g1, uint256 g2))))))",
]);
});
});
});

0 comments on commit 0ceb465

Please sign in to comment.