Skip to content

Commit 3507a74

Browse files
authored
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
1 parent 97797d6 commit 3507a74

File tree

11 files changed

+3182
-11
lines changed

11 files changed

+3182
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master
44

5+
Contributed:
6+
7+
- Add additional namespaced contract tests (Thanks to https://github.com/VargSupercolony)
8+
59
Changes:
610

711
- Adjust `Registry` to augment based on used packages

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Abi', (): void => {
6262
const messageIds = (abi.V3 || abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) =>
6363
label || (
6464
Array.isArray(name)
65-
? name[0]
65+
? name.join('::')
6666
: name
6767
)
6868
);

packages/api-contract/src/Abi/toLatest.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('v1ToLatest', (): void => {
7171

7272
expect(
7373
latest.spec.messages.map(({ label }) => label.toString())
74-
).toEqual(['PSP22Metadata,token_name', 'PSP22Metadata,token_symbol', 'PSP22Metadata,token_decimals', 'PSP22Mintable,mint',
75-
'PSP22,decrease_allowance', 'PSP22,transfer', 'PSP22,approve', 'PSP22,allowance', 'PSP22,transfer_from', 'PSP22,balance_of', 'PSP22,increase_allowance',
76-
'PSP22,total_supply', 'pause', 'unpause']);
74+
).toEqual([
75+
'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'
76+
]);
7777
});
7878

7979
it('has the correct constructor arguments', (): void => {
@@ -110,11 +110,13 @@ describe('v3ToLatest', (): void => {
110110
});
111111

112112
it('has the correct messages', (): void => {
113-
const contract = registry.createType('ContractMetadata', { V3: abis.ink_v3_trait_erc20.V3 });
113+
const contract = registry.createType('ContractMetadata', { V3: abis.ink_v3_traitErc20.V3 });
114114
const latest = v3ToLatest(registry, contract.asV3);
115115

116116
expect(
117117
latest.spec.messages.map(({ label }) => label.toString())
118-
).toEqual(['BaseErc20::total_supply', 'BaseErc20::balance_of', 'BaseErc20::allowance', 'BaseErc20::transfer', 'BaseErc20::approve', 'BaseErc20::transfer_from']);
118+
).toEqual([
119+
'BaseErc20::total_supply', 'BaseErc20::balance_of', 'BaseErc20::allowance', 'BaseErc20::transfer', 'BaseErc20::approve', 'BaseErc20::transfer_from'
120+
]);
119121
});
120122
});

packages/api-contract/src/Abi/toV1.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@ import type { Registry } from '@polkadot/types/types';
77
import { convertSiV0toV1 } from '@polkadot/types';
88
import { objectSpread } from '@polkadot/util';
99

10+
interface Named {
11+
name: unknown;
12+
}
13+
14+
function v0ToV1Names (all: Named[]): unknown[] {
15+
return all.map((e) =>
16+
objectSpread({}, e, {
17+
name: Array.isArray(e.name)
18+
? e.name
19+
: [e.name]
20+
}));
21+
}
22+
1023
export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
1124
return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
25+
spec: objectSpread({}, v0.spec, {
26+
constructors: v0ToV1Names(v0.spec.constructors),
27+
messages: v0ToV1Names(v0.spec.messages)
28+
}),
1229
types: convertSiV0toV1(registry, v0.types)
1330
}));
1431
}

0 commit comments

Comments
 (0)