Add solang tests, re-organize sample layouts (#2760)
* Add solang tests, re-organize sample layouts * Extra lines
This commit is contained in:
@@ -19,72 +19,18 @@ function compareInterface (name: string, messageIds: string[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
interface JSONAbi {
|
||||
spec: {
|
||||
messages: {
|
||||
name: string[] | string
|
||||
}[]
|
||||
}
|
||||
}
|
||||
|
||||
describe('Abi', (): void => {
|
||||
describe('construction', (): void => {
|
||||
it('initializes from a contract ABI (flipper)', (): void => {
|
||||
compareInterface('flipper', ['flip', 'get']);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (incrementer)', (): void => {
|
||||
compareInterface('incrementer', ['inc', 'get']);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc20)', (): void => {
|
||||
compareInterface('erc20', [
|
||||
'total_supply',
|
||||
'balance_of',
|
||||
'allowance',
|
||||
'transfer',
|
||||
'approve',
|
||||
'transfer_from'
|
||||
]);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (delegator)', (): void => {
|
||||
compareInterface('delegator', [
|
||||
'get',
|
||||
'change',
|
||||
'switch'
|
||||
]);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (dns)', (): void => {
|
||||
compareInterface('dns', [
|
||||
'register',
|
||||
'set_address',
|
||||
'transfer',
|
||||
'get_address'
|
||||
]);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc721)', (): void => {
|
||||
compareInterface('erc721', [
|
||||
'balance_of',
|
||||
'owner_of',
|
||||
'get_approved',
|
||||
'is_approved_for_all',
|
||||
'set_approval_for_all',
|
||||
'approve',
|
||||
'transfer',
|
||||
'transfer_from',
|
||||
'mint',
|
||||
'burn'
|
||||
]);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (multisig_plain)', (): void => {
|
||||
compareInterface('multisigPlain', [
|
||||
'add_owner',
|
||||
'remove_owner',
|
||||
'replace_owner',
|
||||
'change_requirement',
|
||||
'submit_transaction',
|
||||
'cancel_transaction',
|
||||
'confirm_transaction',
|
||||
'revoke_confirmation',
|
||||
'invoke_transaction',
|
||||
'eval_transaction'
|
||||
]);
|
||||
Object.entries(abis).forEach(([abiName, abi]) => {
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
compareInterface(abiName, (abi as JSONAbi).spec.messages.map(({ name }) => Array.isArray(name) ? name[0] : name));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,13 +7,11 @@ import path from 'path';
|
||||
import Abi from './Abi';
|
||||
|
||||
import * as testContracts from '../test/contracts';
|
||||
import * as userContracts from '../test/contracts/user';
|
||||
|
||||
const abis: Record<string, any> = { ...testContracts };
|
||||
const userAbis: Record<string, any> = { ...userContracts };
|
||||
|
||||
function compareTypes (name: string): void {
|
||||
const abi = new Abi(abis[name] || userAbis[name]);
|
||||
const abi = new Abi(abis[name]);
|
||||
|
||||
try {
|
||||
const cmpPath = path.join(__dirname, `../test/compare/${name}.test.json`);
|
||||
@@ -32,35 +30,9 @@ function compareTypes (name: string): void {
|
||||
}
|
||||
|
||||
describe('MetaRegistry', (): void => {
|
||||
describe('types', (): void => {
|
||||
it('initializes from a contract ABI (flipper)', (): void => {
|
||||
compareTypes('flipper');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (incrementer)', (): void => {
|
||||
compareTypes('incrementer');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc20)', (): void => {
|
||||
compareTypes('erc20');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (dns)', (): void => {
|
||||
compareTypes('dns');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc721)', (): void => {
|
||||
compareTypes('erc721');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (multisig_plain)', (): void => {
|
||||
compareTypes('multisigPlain');
|
||||
});
|
||||
});
|
||||
|
||||
describe('user ABIs', (): void => {
|
||||
it('initializes from a contract ABI (withString)', (): void => {
|
||||
compareTypes('withString');
|
||||
Object.keys(abis).forEach((abiName) => {
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
compareTypes(abiName);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
[
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
{
|
||||
"info": 12,
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": 6,
|
||||
"type": "u8"
|
||||
},
|
||||
"type": "[u8;32]"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "i32"
|
||||
},
|
||||
{
|
||||
"displayName": "Hash",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "Hash"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u256"
|
||||
}
|
||||
]
|
||||
@@ -1,10 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as delegator } from './delegator.json';
|
||||
export { default as dns } from './dns.json';
|
||||
export { default as erc20 } from './erc20.json';
|
||||
export { default as erc721 } from './erc721.json';
|
||||
export { default as flipper } from './flipper.json';
|
||||
export { default as incrementer } from './incrementer.json';
|
||||
export { default as multisigPlain } from './multisig_plain.json';
|
||||
export * from './ink';
|
||||
export * from './solang';
|
||||
export * from './user';
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as delegator } from './delegator.json';
|
||||
export { default as dns } from './dns.json';
|
||||
export { default as erc20 } from './erc20.json';
|
||||
export { default as erc721 } from './erc721.json';
|
||||
export { default as flipper } from './flipper.json';
|
||||
export { default as incrementer } from './incrementer.json';
|
||||
export { default as multisigPlain } from './multisig_plain.json';
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as ints256 } from './ints256.json';
|
||||
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"contract": {
|
||||
"authors": [
|
||||
"Sean Young <sean@mess.org>"
|
||||
],
|
||||
"description": "Test 256 bits types",
|
||||
"name": "ints256",
|
||||
"version": "0.0.1"
|
||||
},
|
||||
"metadataVersion": "0.1.0",
|
||||
"source": {
|
||||
"compiler": "solang 0.1.4",
|
||||
"hash": "0xa85fb5c61a09d71dce84c15a8bd87e6f4eafac498a1aec3869e8cf7ea4389697",
|
||||
"language": "Solidity 0.1.4"
|
||||
},
|
||||
"spec": {
|
||||
"constructors": [
|
||||
{
|
||||
"args": [],
|
||||
"docs": [
|
||||
""
|
||||
],
|
||||
"name": "new",
|
||||
"selector": "0x861731d5"
|
||||
}
|
||||
],
|
||||
"events": [],
|
||||
"messages": [
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [
|
||||
"Multiply two 256 bit values\n\n"
|
||||
],
|
||||
"mutates": false,
|
||||
"name": "multiply",
|
||||
"payable": false,
|
||||
"return_type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
},
|
||||
"selector": "0x165c4a16"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [
|
||||
"Add two 256 bit values\n\n"
|
||||
],
|
||||
"mutates": false,
|
||||
"name": "add",
|
||||
"payable": false,
|
||||
"return_type": {
|
||||
"display_name": [
|
||||
"u256"
|
||||
],
|
||||
"type": 1
|
||||
},
|
||||
"selector": "0x771602f7"
|
||||
}
|
||||
]
|
||||
},
|
||||
"storage": {
|
||||
"struct": {
|
||||
"fields": []
|
||||
}
|
||||
},
|
||||
"types": [
|
||||
{
|
||||
"def": {
|
||||
"primitive": "u256"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/// @title Test 256 bits types
|
||||
/// @author Sean Young <sean@mess.org>
|
||||
contract ints256 {
|
||||
/// Multiply two 256 bit values
|
||||
function multiply(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// Add two 256 bit values
|
||||
function add(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user