Correct V0/V1 contract def, adjust namespace tests (#4477)

* Correct V0/V1 contract def, adjust namespace tests

* Some failures

* V0 -> V1 conversion with name as Text[]

* CHANGELOG
This commit is contained in:
Jaco
2022-01-20 09:01:17 +02:00
committed by GitHub
parent 97797d64f1
commit 3507a74d60
11 changed files with 3182 additions and 11 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ describe('Abi', (): void => {
const messageIds = (abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) =>
label || (
Array.isArray(name)
? name[0]
? name.join('::')
: name
)
);
@@ -71,9 +71,9 @@ describe('v1ToLatest', (): void => {
expect(
latest.spec.messages.map(({ label }) => label.toString())
).toEqual(['PSP22Metadata,token_name', 'PSP22Metadata,token_symbol', 'PSP22Metadata,token_decimals', 'PSP22Mintable,mint',
'PSP22,decrease_allowance', 'PSP22,transfer', 'PSP22,approve', 'PSP22,allowance', 'PSP22,transfer_from', 'PSP22,balance_of', 'PSP22,increase_allowance',
'PSP22,total_supply', 'pause', 'unpause']);
).toEqual([
'PSP22Metadata::token_name', 'PSP22Metadata::token_symbol', 'PSP22Metadata::token_decimals', 'PSP22Mintable::mint', 'PSP22::decrease_allowance', 'PSP22::transfer', 'PSP22::approve', 'PSP22::allowance', 'PSP22::transfer_from', 'PSP22::balance_of', 'PSP22::increase_allowance', 'PSP22::total_supply', 'pause', 'unpause'
]);
});
it('has the correct constructor arguments', (): void => {
@@ -110,11 +110,13 @@ describe('v3ToLatest', (): void => {
});
it('has the correct messages', (): void => {
const contract = registry.createType('ContractMetadata', { V3: abis.ink_v3_trait_erc20.V3 });
const contract = registry.createType('ContractMetadata', { V3: abis.ink_v3_traitErc20.V3 });
const latest = v3ToLatest(registry, contract.asV3);
expect(
latest.spec.messages.map(({ label }) => label.toString())
).toEqual(['BaseErc20::total_supply', 'BaseErc20::balance_of', 'BaseErc20::allowance', 'BaseErc20::transfer', 'BaseErc20::approve', 'BaseErc20::transfer_from']);
).toEqual([
'BaseErc20::total_supply', 'BaseErc20::balance_of', 'BaseErc20::allowance', 'BaseErc20::transfer', 'BaseErc20::approve', 'BaseErc20::transfer_from'
]);
});
});
+17
View File
@@ -7,8 +7,25 @@ import type { Registry } from '@polkadot/types/types';
import { convertSiV0toV1 } from '@polkadot/types';
import { objectSpread } from '@polkadot/util';
interface Named {
name: unknown;
}
function v0ToV1Names (all: Named[]): unknown[] {
return all.map((e) =>
objectSpread({}, e, {
name: Array.isArray(e.name)
? e.name
: [e.name]
}));
}
export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
spec: objectSpread({}, v0.spec, {
constructors: v0ToV1Names(v0.spec.constructors),
messages: v0ToV1Names(v0.spec.messages)
}),
types: convertSiV0toV1(registry, v0.types)
}));
}
@@ -0,0 +1,529 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "u128",
"docs": [],
"namespace": ""
},
{
"info": "Struct",
"lookupIndex": 1,
"lookupName": "InkStorageCollectionsStashHeader",
"type": "{\"lastVacant\":\"u32\",\"len\":\"u32\",\"lenEntries\":\"u32\"}",
"docs": [],
"namespace": "ink_storage::collections::stash::Header",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "lastVacant",
"typeName": "Index"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "len",
"typeName": "u32"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "lenEntries",
"typeName": "u32"
}
]
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": ""
},
{
"info": "Enum",
"lookupIndex": 3,
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"AccountId\"}}",
"docs": [],
"namespace": "ink_storage::collections::stash::Entry",
"sub": [
{
"docs": [],
"info": "Si",
"lookupIndex": 7,
"lookupName": "InkStorageCollectionsStashVacantEntry",
"type": "Lookup7",
"typeName": "VacantEntry",
"index": 0,
"name": "Vacant"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId",
"typeName": "T",
"index": 1,
"name": "Occupied"
}
]
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "VecFixed",
"lookupIndex": 5,
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
},
{
"info": "Struct",
"lookupIndex": 7,
"lookupName": "InkStorageCollectionsStashVacantEntry",
"type": "{\"next\":\"u32\",\"prev\":\"u32\"}",
"docs": [],
"namespace": "ink_storage::collections::stash::VacantEntry",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "next",
"typeName": "Index"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "prev",
"typeName": "Index"
}
]
},
{
"info": "Struct",
"lookupIndex": 8,
"type": "{\"value\":\"u128\",\"keyIndex\":\"u32\"}",
"docs": [],
"namespace": "ink_storage::collections::hashmap::ValueEntry",
"sub": [
{
"info": "Plain",
"lookupIndex": 0,
"type": "u128",
"docs": [],
"namespace": "",
"name": "value",
"typeName": "V"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "keyIndex",
"typeName": "KeyIndex"
}
]
},
{
"info": "Enum",
"lookupIndex": 9,
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}",
"docs": [],
"namespace": "ink_storage::collections::stash::Entry",
"sub": [
{
"docs": [],
"info": "Si",
"lookupIndex": 7,
"lookupName": "InkStorageCollectionsStashVacantEntry",
"type": "Lookup7",
"typeName": "VacantEntry",
"index": 0,
"name": "Vacant"
},
{
"info": "Tuple",
"lookupIndex": 10,
"type": "(AccountId,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
],
"typeName": "T",
"index": 1,
"name": "Occupied"
}
]
},
{
"info": "Tuple",
"lookupIndex": 10,
"type": "(AccountId,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
]
},
{
"info": "Plain",
"lookupIndex": 11,
"type": "Text",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 12,
"type": "bool",
"docs": [],
"namespace": ""
},
{
"info": "Enum",
"lookupIndex": 13,
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"u32\"}}",
"docs": [],
"namespace": "ink_storage::collections::stash::Entry",
"sub": [
{
"docs": [],
"info": "Si",
"lookupIndex": 7,
"lookupName": "InkStorageCollectionsStashVacantEntry",
"type": "Lookup7",
"typeName": "VacantEntry",
"index": 0,
"name": "Vacant"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"typeName": "T",
"index": 1,
"name": "Occupied"
}
]
},
{
"info": "Struct",
"lookupIndex": 14,
"type": "{\"value\":\"u32\",\"keyIndex\":\"u32\"}",
"docs": [],
"namespace": "ink_storage::collections::hashmap::ValueEntry",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "value",
"typeName": "V"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "keyIndex",
"typeName": "KeyIndex"
}
]
},
{
"info": "Enum",
"lookupIndex": 15,
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(u32,AccountId)\"}}",
"docs": [],
"namespace": "ink_storage::collections::stash::Entry",
"sub": [
{
"docs": [],
"info": "Si",
"lookupIndex": 7,
"lookupName": "InkStorageCollectionsStashVacantEntry",
"type": "Lookup7",
"typeName": "VacantEntry",
"index": 0,
"name": "Vacant"
},
{
"info": "Tuple",
"lookupIndex": 16,
"type": "(u32,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
],
"typeName": "T",
"index": 1,
"name": "Occupied"
}
]
},
{
"info": "Tuple",
"lookupIndex": 16,
"type": "(u32,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
]
},
{
"info": "Struct",
"lookupIndex": 17,
"type": "{\"value\":\"Null\",\"keyIndex\":\"u32\"}",
"docs": [],
"namespace": "ink_storage::collections::hashmap::ValueEntry",
"sub": [
{
"info": "Null",
"lookupIndex": 18,
"type": "Null",
"docs": [],
"namespace": "",
"name": "value",
"typeName": "V"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u32",
"docs": [],
"namespace": "",
"name": "keyIndex",
"typeName": "KeyIndex"
}
]
},
{
"info": "Null",
"lookupIndex": 18,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"info": "Option",
"lookupIndex": 19,
"type": "Option<Text>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 11,
"type": "Text",
"docs": [],
"namespace": ""
}
},
{
"info": "Result",
"lookupIndex": 20,
"type": "Result<Null, ContractsErrorsPsp22Psp22Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 18,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 21,
"lookupName": "ContractsErrorsPsp22Psp22Error",
"type": "Lookup21"
}
]
},
{
"info": "Enum",
"lookupIndex": 21,
"lookupName": "ContractsErrorsPsp22Psp22Error",
"type": "{\"_enum\":{\"Custom\":\"Text\",\"InsufficientBalance\":\"Null\",\"InsufficientAllowance\":\"Null\",\"ZeroRecipientAddress\":\"Null\",\"ZeroSenderAddress\":\"Null\",\"SafeTransferCheckFailed\":\"Text\"}}",
"docs": [],
"namespace": "contracts::traits::errors::psp22::PSP22Error",
"sub": [
{
"info": "Plain",
"lookupIndex": 11,
"type": "Text",
"docs": [],
"namespace": "",
"typeName": "Text",
"index": 0,
"name": "Custom"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "InsufficientBalance"
},
{
"info": "Null",
"type": "Null",
"index": 2,
"name": "InsufficientAllowance"
},
{
"info": "Null",
"type": "Null",
"index": 3,
"name": "ZeroRecipientAddress"
},
{
"info": "Null",
"type": "Null",
"index": 4,
"name": "ZeroSenderAddress"
},
{
"info": "Plain",
"lookupIndex": 11,
"type": "Text",
"docs": [],
"namespace": "",
"typeName": "Text",
"index": 5,
"name": "SafeTransferCheckFailed"
}
]
},
{
"info": "Plain",
"lookupIndex": 22,
"type": "Bytes",
"docs": [],
"namespace": ""
},
{
"info": "Option",
"lookupIndex": 23,
"type": "Option<AccountId>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
}
]
@@ -0,0 +1,204 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "u128",
"docs": [],
"namespace": ""
},
{
"info": "Struct",
"lookupIndex": 1,
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping",
"sub": [
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "Key",
"name": "offsetKey"
}
]
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "VecFixed",
"lookupIndex": 3,
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "[u8;32]"
},
{
"info": "Struct",
"lookupIndex": 6,
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping",
"sub": [
{
"info": "VecFixed",
"lookupIndex": 5,
"lookupName": "InkPrimitivesKey",
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "u8",
"docs": [],
"namespace": ""
},
"typeName": "Key",
"name": "offsetKey"
}
]
},
{
"info": "Tuple",
"lookupIndex": 7,
"type": "(AccountId,AccountId)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
]
},
{
"info": "Result",
"lookupIndex": 8,
"type": "Result<Null, TraitErc20Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 9,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 10,
"lookupName": "TraitErc20Erc20Error",
"type": "Lookup10"
}
]
},
{
"info": "Null",
"lookupIndex": 9,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"info": "Enum",
"lookupIndex": 10,
"lookupName": "TraitErc20Erc20Error",
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
"docs": [],
"namespace": "trait_erc20::erc20::Error",
"sub": [
{
"info": "Null",
"type": "Null",
"index": 0,
"name": "InsufficientBalance"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "InsufficientAllowance"
}
]
},
{
"info": "Option",
"lookupIndex": 11,
"type": "Option<AccountId>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 2,
"type": "AccountId",
"docs": [],
"namespace": "ink_env::types::AccountId",
"lookupNameRoot": "InkEnvAccountId"
}
}
]
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long