Skip to content

Commit 4cb8462

Browse files
authored
Cleanup ABI encodeType, fix test compare (#1616)
1 parent 1d671d5 commit 4cb8462

File tree

6 files changed

+1717
-246
lines changed

6 files changed

+1717
-246
lines changed

packages/api-contract/src/MetaRegistry.spec.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,41 @@
22
// This software may be modified and distributed under the terms
33
// of the Apache-2.0 license. See the LICENSE file for details.
44

5-
import fs from 'fs';
6-
import path from 'path';
75
import { TypeRegistry } from '@polkadot/types';
86

97
import MetaRegistry from './MetaRegistry';
108

119
import erc20Abi from '../test/contracts/Erc20.json';
10+
import erc20Cmp from '../test/compare/erc20.test.json';
1211
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+
}
1325

1426
describe('MetaRegistry', (): void => {
1527
const registry = new TypeRegistry();
1628

1729
describe('construction', (): void => {
1830
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);
2532
});
2633

2734
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+
});
3237

33-
expect(true).toBe(true);
38+
it('initializes from a contract ABI (Other, test001)', (): void => {
39+
compare(new MetaRegistry(registry, test001Abi), test001Cmp);
3440
});
3541
});
3642
});

0 commit comments

Comments
 (0)