diff --git a/packages/go-gen/src/main.rs b/packages/go-gen/src/main.rs index 1a4f8278f2..ab853a47c6 100644 --- a/packages/go-gen/src/main.rs +++ b/packages/go-gen/src/main.rs @@ -524,4 +524,26 @@ mod tests { "#, ); } + + #[test] + fn timestamp_works() { + use cosmwasm_std::Timestamp; + + #[cw_serde] + struct A { + a: Timestamp, + b: Option, + } + + let code = generate_go(cosmwasm_schema::schema_for!(A)).unwrap(); + assert_code_eq( + code, + r#" + type A struct { + A Uint64 `json:"a"` + B *Uint64 `json:"b,omitempty"` + } + "#, + ); + } } diff --git a/packages/go-gen/src/schema.rs b/packages/go-gen/src/schema.rs index 9ee6a8ffcf..97fe28bc5d 100644 --- a/packages/go-gen/src/schema.rs +++ b/packages/go-gen/src/schema.rs @@ -259,9 +259,9 @@ pub fn documentation(schema: &SchemaObject) -> Option { /// If the given type is not a special type, returns `None`. pub fn custom_type_of(ty: &str) -> Option<&str> { match ty { - "Uint64" => Some("string"), + "Uint64" => Some("Uint64"), "Uint128" => Some("string"), - "Int64" => Some("string"), + "Int64" => Some("Int64"), "Int128" => Some("string"), "Binary" => Some("[]byte"), "HexBinary" => Some("Checksum"), @@ -270,7 +270,7 @@ pub fn custom_type_of(ty: &str) -> Option<&str> { "Decimal256" => Some("string"), "SignedDecimal" => Some("string"), "SignedDecimal256" => Some("string"), - "Timestamp" => Some("uint64"), + "Timestamp" => Some("Uint64"), _ => None, } } diff --git a/packages/go-gen/tests/cosmwasm_std__IbcMsg.go b/packages/go-gen/tests/cosmwasm_std__IbcMsg.go index d8165ba957..e9699c1161 100644 --- a/packages/go-gen/tests/cosmwasm_std__IbcMsg.go +++ b/packages/go-gen/tests/cosmwasm_std__IbcMsg.go @@ -30,7 +30,7 @@ type Coin struct { type IBCTimeout struct { Block *IBCTimeoutBlock `json:"block,omitempty"` // in wasmvm, this does not have "omitempty" // Nanoseconds since UNIX epoch - Timestamp uint64 `json:"timestamp,omitempty"` // wasmvm has a "string" in here too + Timestamp *Uint64 `json:"timestamp,omitempty"` } // IBCTimeoutBlock Height is a monotonically increasing data type