Open KaiserKarel opened 3 years ago
@KaiserKarel Are you using @redspot/known-types. If so then there is a real possibility of a conflict, if not then it should be fine.
So I managed to track down parts of my error to incorrect configurations, however it seems that sometimes, redspot also fails to create a type for an event:
createType({"foo":"AccountId","bar":"Text"}):: decodeU8a: failed at 0x5901000000000000… on bar: Text:: Text: required length less than remainder, expected at least 88, found 50
where bar is defined as type Bar = String
.
Any clues what causes this?
First you can check if the types have been correctly injected into the api.registry. For example:
...
networks: {
development: {
endpoint: "wss://kusama-rpc.polkadot.io",
gasLimit: "400000000000",
types: {
foo: "Text",
},
},
},
...
npx redspot console --no-compile
This indicates that the configuration is OK.
If there is still a problem, then you can post your code and I will check what the problem is.
Thanks, useful tool to sanity check.
This leads me to the following error:
> network.api.registry.createType({"foo":"AccountId","bar":"Text"}).toHex()
Uncaught Error: createType([object Object]):: Cannot read property 'trim' of undefined
at TypeRegistry.createType (/home/karel/Privi/Privi-Ink-Contract/node_modules/@polkadot/types/create/registry.cjs:308:39)
at createType (/home/karel/Privi/Privi-Ink-Contract/node_modules/@polkadot/types/create/createType.cjs:67:10)
at createTypeUnsafe (/home/karel/Privi/Privi-Ink-Contract/node_modules/@polkadot/types/create/createType.cjs:55:11)
Of course you can't do that. there is no problem with this error.
The first parameter of createType is the type name and the second parameter is the value. https://polkadot.js.org/docs/api/start/types.create
If you want to define a structure, you can do something like this:
...
types: {
baz: {
foo: "AccountId",
bar: "Text",
},
},
...
Then run:
network.api.registry.createType('baz', {foo: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', bar: 'hhh'}).toHex()
Yes but this is exactly the error message that is happening during a test. :)
await expect(
contract.connect(receiver).tx.doFoo({
...
})
).to.emit(contract, 'Baz');
Will sometimes fail with createType({"foo":"AccountId","bar":"Text"}):: decodeU8a: failed at 0x5901000000000000… on bar: Text:: Text: required length less than remainder, expected at least 88, found 50
, and other times just work.
So I'm wondering why it is attempting to create that type, and why it only sometimes fails.
I'm thinking that it is due to an event; based on the fields. Do events need to be registered as well?
decodeU8a: failed at 0x5901000000000000… on bar: Text:: Text: required length less than remainder, expected at least 88, found 50
I think the type should already be injected. This error does not say that the type cannot be found.
But I'm not quite sure why it fails to decode. https://github.com/polkadot-js/api/blob/121bfc79132283d802299cec4a82c50f2a6ecc8f/packages/types/src/primitive/Text.ts#L14-L38
So it seems like replacing String with Vec
Are you using the latest redspot, 0.11.6-3? and if you can provide a test case, we'll debug it and find out what's going wrong.
I'll write a reproducible example this weekend
Even though we registered types in the configuration, sometimes they'll still fail to be created. I thought that might be due to incorrect order of definitions and usages, but that does not seem to be the case. Are there known bugs here?