Cleanup ABI encodeType, fix test compare (#1616)

This commit is contained in:
Jaco Greeff
2019-11-28 12:42:49 +01:00
committed by GitHub
parent 1d671d531c
commit 4cb8462d50
6 changed files with 1717 additions and 246 deletions
+19 -13
View File
@@ -2,35 +2,41 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import fs from 'fs';
import path from 'path';
import { TypeRegistry } from '@polkadot/types';
import MetaRegistry from './MetaRegistry';
import erc20Abi from '../test/contracts/Erc20.json';
import erc20Cmp from '../test/compare/erc20.test.json';
import sharedVecAbi from '../test/contracts/SharedVecV2.json';
import sharedVecCmp from '../test/compare/shared-vec.test.json';
import test001Abi from '../test/abi/test001.json';
import test001Cmp from '../test/compare/test001.cmp.json';
function compare (meta: MetaRegistry, other: any): void {
try {
expect(meta.typeDefs).toEqual(other);
} catch (error) {
console.error(JSON.stringify(meta.typeDefs));
throw error;
}
}
describe('MetaRegistry', (): void => {
const registry = new TypeRegistry();
describe('construction', (): void => {
it('initializes from a contract ABI (ERC20)', (): void => {
const metaRegistry = new MetaRegistry(registry, erc20Abi);
fs.writeFile(path.join(__dirname, '../test/compare/erc20.test.json'), JSON.stringify(metaRegistry.typeDefs, null, 2), function (err): void {
if (err) throw err;
});
expect(true).toBe(true);
compare(new MetaRegistry(registry, erc20Abi), erc20Cmp);
});
it('initializes from a contract ABI (SharedVec)', (): void => {
const metaRegistry = new MetaRegistry(registry, sharedVecAbi);
fs.writeFile(path.join(__dirname, '../test/compare/shared-vec.test.json'), JSON.stringify(metaRegistry.typeDefs, null, 2), function (err): void {
if (err) throw err;
});
compare(new MetaRegistry(registry, sharedVecAbi), sharedVecCmp);
});
expect(true).toBe(true);
it('initializes from a contract ABI (Other, test001)', (): void => {
compare(new MetaRegistry(registry, test001Abi), test001Cmp);
});
});
});