1 | const contract = require("@truffle/contract");
|
2 |
|
3 | const Schema = require("../index.js");
|
4 | const assert = require("assert");
|
5 |
|
6 | const MetaCoin = require("./MetaCoin.json");
|
7 |
|
8 |
|
9 |
|
10 | const MetaCoinInvalid = require("./MetaCoin-invalid.json");
|
11 |
|
12 | const validatedMetaCoin = {
|
13 | "69420": {
|
14 | address: "0x1111111111111111111111111111111111111111",
|
15 | events: {
|
16 | "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
17 | anonymous: false,
|
18 | inputs: [
|
19 | {
|
20 | indexed: true,
|
21 | internalType: "address",
|
22 | name: "_from",
|
23 | type: "address"
|
24 | },
|
25 | {
|
26 | indexed: true,
|
27 | internalType: "address",
|
28 | name: "_to",
|
29 | type: "address"
|
30 | },
|
31 | {
|
32 | indexed: false,
|
33 | internalType: "uint256",
|
34 | name: "_value",
|
35 | type: "uint256"
|
36 | }
|
37 | ],
|
38 | name: "Transfer",
|
39 | type: "event"
|
40 | }
|
41 | },
|
42 | links: {
|
43 | ConvertLib: "0xB5AF56dF69655d7a68d248EA963eD1416Dd053E2"
|
44 | },
|
45 | transactionHash:
|
46 | "0x1111111111111111111111111111111111111111111111111111111111111111"
|
47 | }
|
48 | };
|
49 |
|
50 | const prepareContract = (contract, network) => {
|
51 | contract.setNetwork(network);
|
52 | contract.address = "0x1111111111111111111111111111111111111111";
|
53 | contract.transactionHash =
|
54 | "0x1111111111111111111111111111111111111111111111111111111111111111";
|
55 | };
|
56 |
|
57 | describe("networks", function() {
|
58 | let MetaCoinContractGood, MetaCoinContractBad;
|
59 |
|
60 | beforeEach(() => {
|
61 | MetaCoinContractGood = contract(MetaCoin);
|
62 | prepareContract(MetaCoinContractGood, 69420);
|
63 |
|
64 | MetaCoinContractBad = contract(MetaCoinInvalid);
|
65 | prepareContract(MetaCoinContractBad, 69420);
|
66 | });
|
67 |
|
68 | describe("normalized has correct events ", function() {
|
69 | it("when starting with valid events schema", function() {
|
70 | const normalized = Schema.normalize(MetaCoinContractGood);
|
71 | assert.deepEqual(normalized.networks, validatedMetaCoin);
|
72 | });
|
73 |
|
74 | it("when starting with invalid events schema", function() {
|
75 | const normalized = Schema.normalize(MetaCoinContractBad);
|
76 | assert.deepEqual(normalized.networks, validatedMetaCoin);
|
77 | });
|
78 | });
|
79 | });
|