|
2 | 2 | // This software may be modified and distributed under the terms |
3 | 3 | // of the Apache-2.0 license. See the LICENSE file for details. |
4 | 4 |
|
5 | | -import fs from 'fs'; |
6 | | -import path from 'path'; |
7 | 5 | import { TypeRegistry } from '@polkadot/types'; |
8 | 6 |
|
9 | 7 | import MetaRegistry from './MetaRegistry'; |
10 | 8 |
|
11 | 9 | import erc20Abi from '../test/contracts/Erc20.json'; |
| 10 | +import erc20Cmp from '../test/compare/erc20.test.json'; |
12 | 11 | import sharedVecAbi from '../test/contracts/SharedVecV2.json'; |
| 12 | +import sharedVecCmp from '../test/compare/shared-vec.test.json'; |
| 13 | +import test001Abi from '../test/abi/test001.json'; |
| 14 | +import test001Cmp from '../test/compare/test001.cmp.json'; |
| 15 | + |
| 16 | +function compare (meta: MetaRegistry, other: any): void { |
| 17 | + try { |
| 18 | + expect(meta.typeDefs).toEqual(other); |
| 19 | + } catch (error) { |
| 20 | + console.error(JSON.stringify(meta.typeDefs)); |
| 21 | + |
| 22 | + throw error; |
| 23 | + } |
| 24 | +} |
13 | 25 |
|
14 | 26 | describe('MetaRegistry', (): void => { |
15 | 27 | const registry = new TypeRegistry(); |
16 | 28 |
|
17 | 29 | describe('construction', (): void => { |
18 | 30 | it('initializes from a contract ABI (ERC20)', (): void => { |
19 | | - const metaRegistry = new MetaRegistry(registry, erc20Abi); |
20 | | - fs.writeFile(path.join(__dirname, '../test/compare/erc20.test.json'), JSON.stringify(metaRegistry.typeDefs, null, 2), function (err): void { |
21 | | - if (err) throw err; |
22 | | - }); |
23 | | - |
24 | | - expect(true).toBe(true); |
| 31 | + compare(new MetaRegistry(registry, erc20Abi), erc20Cmp); |
25 | 32 | }); |
26 | 33 |
|
27 | 34 | it('initializes from a contract ABI (SharedVec)', (): void => { |
28 | | - const metaRegistry = new MetaRegistry(registry, sharedVecAbi); |
29 | | - fs.writeFile(path.join(__dirname, '../test/compare/shared-vec.test.json'), JSON.stringify(metaRegistry.typeDefs, null, 2), function (err): void { |
30 | | - if (err) throw err; |
31 | | - }); |
| 35 | + compare(new MetaRegistry(registry, sharedVecAbi), sharedVecCmp); |
| 36 | + }); |
32 | 37 |
|
33 | | - expect(true).toBe(true); |
| 38 | + it('initializes from a contract ABI (Other, test001)', (): void => { |
| 39 | + compare(new MetaRegistry(registry, test001Abi), test001Cmp); |
34 | 40 | }); |
35 | 41 | }); |
36 | 42 | }); |
0 commit comments