CosmWasm / ts-codegen

Convert your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
https://cosmology.zone/products/ts-codegen
Apache License 2.0
116 stars 27 forks source link

question: TypeError: Cannot create property 'title' on boolean 'true' #139

Closed dzmitry-lahoda closed 4 months ago

dzmitry-lahoda commented 5 months ago

I did not had bug, just got it now (tried old and latest version of generator):

/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/utils/schemas.js:72
                Types[typ].definitions[key].title = key;
                                                  ^

TypeError: Cannot create property 'title' on boolean 'true'
    at findAndParseTypes (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/utils/schemas.js:72:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TypesPlugin.doRender (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/plugins/types.js:46:26)
    at async TypesPlugin.render (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/plugins/plugin-base.js:56:25)
    at async TSBuilder.render (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/builder/builder.js:114:25)
    at async TSBuilder.process (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/builder/builder.js:109:13)
    at async TSBuilder.build (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/builder/builder.js:97:9)
    at async exports.default (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/index.js:40:5)
    at async exports.default [as generate] (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/commands/generate.js:165:5)
    at async cli (/home/dz/github.com/ComposableFi/composable-vm/contracts/cosmwasm/node_modules/@cosmwasm/ts-codegen/cli.js:18:9)

Node.js v20.11.1

I updated version of CW from 1.2.X to 1.5.X. Also added some more msgs into contract.

dzmitry-lahoda commented 5 months ago

based on these types https://github.com/ComposableFi/composable-vm/blob/main/schema/cvm-runtime.json

dzmitry-lahoda commented 5 months ago

found root cause

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(
    all(
        feature = "json-schema", // all(feature = "json-schema", not(target_arch = "wasm32")),
        not(feature = "xcm")
    ),
    derive(schemars::JsonSchema)
)]
pub enum ForeignAssetId {
    IbcIcs20(PrefixedDenom),

    // `xcm::VersionedMultiLocation` not validated, until XCM supports std wasm or CW no_std (or copy paste)
    Xcm(serde_cw_value::Value),
}

so it cannot type object with type JSON (in rust it is serde_cw_value::Value)

dzmitry-lahoda commented 4 months ago

replaced with binary for now (XCM serde is SCALE).

observation that python model generator from schema fails on same JSON schema.

either shemars are buggy, or serde_cw_value gives buggy schema, or ts/py generators have bug, or have serde_cw_value as type in schema is useless

pyramation commented 4 months ago

so does it work now? sounds like a Rust issue?

Can you provide a schema?

dzmitry-lahoda commented 4 months ago

so does it work now? sounds like a Rust issue?

@pyramation I does not look like exactly Rust issue. Let me explain.

I have cosmwasm contract with kind of valid JSON schema. I generate json file with schema out of it.

But ts generator fails to generate typescript code.

As soon as it can be agreed that JSON schema here is valid https://github.com/ComposableFi/composable-vm/blob/c38dd934eff95f5ca73faa5e1a77bd785a6f1562/schema/cvm-runtime.json#L950 , ts gen should not fail.

dzmitry-lahoda commented 4 months ago

ahaha. right https://github.com/ComposableFi/composable-vm/blob/c38dd934eff95f5ca73faa5e1a77bd785a6f1562/schema/cvm-runtime.json#L2250 . it is not valid. fun