Skip to content

Commit ba1f761

Browse files
authored
Merge pull request #907 from CosmWasm/test-timeout-serializations
Change IbcTimeout back to struct
2 parents 8740a27 + dee80cb commit ba1f761

File tree

11 files changed

+220
-294
lines changed

11 files changed

+220
-294
lines changed

IBC.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ pub enum IbcMsg {
4242
/// two timeout fields we ensure that at least one timeout is set.
4343
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
4444
#[serde(rename_all = "snake_case")]
45-
pub enum IbcTimeout {
46-
/// Block timestamp (nanoseconds since UNIX epoch) after which the packet times out
47-
/// (measured on the remote chain).
48-
Timestamp(Timestamp),
49-
/// Block after which the packet times out (measured on remote chain).
50-
Block(IbcTimeoutBlock),
51-
/// Use this to set both timestamp and block timeout. The package then times out once
52-
/// the first of both timeouts is hit.
53-
Both {
54-
timestamp: Timestamp,
55-
block: IbcTimeoutBlock,
56-
},
45+
pub struct IbcTimeout {
46+
block: Option<IbcTimeoutBlock>,
47+
timestamp: Option<Timestamp>,
5748
}
5849
```
5950

@@ -309,13 +300,7 @@ pub struct IbcPacket {
309300
pub dest: IbcEndpoint,
310301
/// The sequence number of the packet on the given channel
311302
pub sequence: u64,
312-
/// block height after which the packet times out.
313-
/// at least one of timeout_block, timeout_timestamp is required
314-
pub timeout_block: Option<IbcTimeoutBlock>,
315-
/// block timestamp (nanoseconds since UNIX epoch) after which the packet times out.
316-
/// See https://golang.org/pkg/time/#Time.UnixNano
317-
/// at least one of timeout_block, timeout_timestamp is required
318-
pub timeout_timestamp: Option<u64>,
303+
pub timeout: IbcTimeout,
319304
}
320305
```
321306

contracts/ibc-reflect-send/schema/execute_msg.json

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -436,59 +436,29 @@
436436
},
437437
"IbcTimeout": {
438438
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
439-
"anyOf": [
440-
{
441-
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
442-
"type": "object",
443-
"required": [
444-
"timestamp"
445-
],
446-
"properties": {
447-
"timestamp": {
448-
"$ref": "#/definitions/Timestamp"
449-
}
450-
},
451-
"additionalProperties": false
452-
},
453-
{
454-
"description": "Block after which the packet times out (measured on remote chain).",
455-
"type": "object",
456-
"required": [
457-
"block"
458-
],
459-
"properties": {
460-
"block": {
439+
"type": "object",
440+
"properties": {
441+
"block": {
442+
"anyOf": [
443+
{
461444
"$ref": "#/definitions/IbcTimeoutBlock"
445+
},
446+
{
447+
"type": "null"
462448
}
463-
},
464-
"additionalProperties": false
449+
]
465450
},
466-
{
467-
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
468-
"type": "object",
469-
"required": [
470-
"both"
471-
],
472-
"properties": {
473-
"both": {
474-
"type": "object",
475-
"required": [
476-
"block",
477-
"timestamp"
478-
],
479-
"properties": {
480-
"block": {
481-
"$ref": "#/definitions/IbcTimeoutBlock"
482-
},
483-
"timestamp": {
484-
"$ref": "#/definitions/Timestamp"
485-
}
486-
}
451+
"timestamp": {
452+
"anyOf": [
453+
{
454+
"$ref": "#/definitions/Timestamp"
455+
},
456+
{
457+
"type": "null"
487458
}
488-
},
489-
"additionalProperties": false
459+
]
490460
}
491-
]
461+
}
492462
},
493463
"IbcTimeoutBlock": {
494464
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",

contracts/ibc-reflect-send/schema/packet_msg.json

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -389,59 +389,29 @@
389389
},
390390
"IbcTimeout": {
391391
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
392-
"anyOf": [
393-
{
394-
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
395-
"type": "object",
396-
"required": [
397-
"timestamp"
398-
],
399-
"properties": {
400-
"timestamp": {
401-
"$ref": "#/definitions/Timestamp"
402-
}
403-
},
404-
"additionalProperties": false
405-
},
406-
{
407-
"description": "Block after which the packet times out (measured on remote chain).",
408-
"type": "object",
409-
"required": [
410-
"block"
411-
],
412-
"properties": {
413-
"block": {
392+
"type": "object",
393+
"properties": {
394+
"block": {
395+
"anyOf": [
396+
{
414397
"$ref": "#/definitions/IbcTimeoutBlock"
398+
},
399+
{
400+
"type": "null"
415401
}
416-
},
417-
"additionalProperties": false
402+
]
418403
},
419-
{
420-
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
421-
"type": "object",
422-
"required": [
423-
"both"
424-
],
425-
"properties": {
426-
"both": {
427-
"type": "object",
428-
"required": [
429-
"block",
430-
"timestamp"
431-
],
432-
"properties": {
433-
"block": {
434-
"$ref": "#/definitions/IbcTimeoutBlock"
435-
},
436-
"timestamp": {
437-
"$ref": "#/definitions/Timestamp"
438-
}
439-
}
404+
"timestamp": {
405+
"anyOf": [
406+
{
407+
"$ref": "#/definitions/Timestamp"
408+
},
409+
{
410+
"type": "null"
440411
}
441-
},
442-
"additionalProperties": false
412+
]
443413
}
444-
]
414+
}
445415
},
446416
"IbcTimeoutBlock": {
447417
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",

contracts/ibc-reflect-send/src/ibc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ mod tests {
255255
mock_dependencies, mock_env, mock_ibc_channel, mock_ibc_packet_ack, mock_info, MockApi,
256256
MockQuerier, MockStorage,
257257
};
258-
use cosmwasm_std::{coin, coins, BankMsg, CosmosMsg, IbcTimeout, OwnedDeps};
258+
use cosmwasm_std::{coin, coins, BankMsg, CosmosMsg, OwnedDeps};
259259

260260
const CREATOR: &str = "creator";
261261

@@ -445,7 +445,8 @@ mod tests {
445445
assert_eq!(transfer_channel_id, channel_id.as_str());
446446
assert_eq!(remote_addr, to_address.as_str());
447447
assert_eq!(&coin(12344, "utrgd"), amount);
448-
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
448+
assert!(timeout.block().is_none());
449+
assert!(timeout.timestamp().is_some());
449450
}
450451
o => panic!("unexpected message: {:?}", o),
451452
}

contracts/ibc-reflect-send/tests/integration.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use cosmwasm_std::testing::{mock_ibc_channel, mock_ibc_packet_ack};
2121
use cosmwasm_std::{
2222
attr, coin, coins, to_binary, BankMsg, CosmosMsg, Empty, IbcAcknowledgement, IbcBasicResponse,
23-
IbcMsg, IbcOrder, IbcTimeout, Response,
23+
IbcMsg, IbcOrder, Response,
2424
};
2525
use cosmwasm_vm::testing::{
2626
execute, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, instantiate, mock_env,
@@ -239,7 +239,8 @@ fn send_remote_funds() {
239239
assert_eq!(transfer_channel_id, channel_id.as_str());
240240
assert_eq!(remote_addr, to_address.as_str());
241241
assert_eq!(&coin(12344, "utrgd"), amount);
242-
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
242+
assert!(timeout.block().is_none());
243+
assert!(timeout.timestamp().is_some());
243244
}
244245
o => panic!("unexpected message: {:?}", o),
245246
}

contracts/ibc-reflect/schema/packet_msg.json

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -388,59 +388,29 @@
388388
},
389389
"IbcTimeout": {
390390
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
391-
"anyOf": [
392-
{
393-
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
394-
"type": "object",
395-
"required": [
396-
"timestamp"
397-
],
398-
"properties": {
399-
"timestamp": {
400-
"$ref": "#/definitions/Timestamp"
401-
}
402-
},
403-
"additionalProperties": false
404-
},
405-
{
406-
"description": "Block after which the packet times out (measured on remote chain).",
407-
"type": "object",
408-
"required": [
409-
"block"
410-
],
411-
"properties": {
412-
"block": {
391+
"type": "object",
392+
"properties": {
393+
"block": {
394+
"anyOf": [
395+
{
413396
"$ref": "#/definitions/IbcTimeoutBlock"
397+
},
398+
{
399+
"type": "null"
414400
}
415-
},
416-
"additionalProperties": false
401+
]
417402
},
418-
{
419-
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
420-
"type": "object",
421-
"required": [
422-
"both"
423-
],
424-
"properties": {
425-
"both": {
426-
"type": "object",
427-
"required": [
428-
"block",
429-
"timestamp"
430-
],
431-
"properties": {
432-
"block": {
433-
"$ref": "#/definitions/IbcTimeoutBlock"
434-
},
435-
"timestamp": {
436-
"$ref": "#/definitions/Timestamp"
437-
}
438-
}
403+
"timestamp": {
404+
"anyOf": [
405+
{
406+
"$ref": "#/definitions/Timestamp"
407+
},
408+
{
409+
"type": "null"
439410
}
440-
},
441-
"additionalProperties": false
411+
]
442412
}
443-
]
413+
}
444414
},
445415
"IbcTimeoutBlock": {
446416
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",

contracts/reflect/schema/execute_msg.json

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -432,59 +432,29 @@
432432
},
433433
"IbcTimeout": {
434434
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
435-
"anyOf": [
436-
{
437-
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
438-
"type": "object",
439-
"required": [
440-
"timestamp"
441-
],
442-
"properties": {
443-
"timestamp": {
444-
"$ref": "#/definitions/Timestamp"
445-
}
446-
},
447-
"additionalProperties": false
448-
},
449-
{
450-
"description": "Block after which the packet times out (measured on remote chain).",
451-
"type": "object",
452-
"required": [
453-
"block"
454-
],
455-
"properties": {
456-
"block": {
435+
"type": "object",
436+
"properties": {
437+
"block": {
438+
"anyOf": [
439+
{
457440
"$ref": "#/definitions/IbcTimeoutBlock"
441+
},
442+
{
443+
"type": "null"
458444
}
459-
},
460-
"additionalProperties": false
445+
]
461446
},
462-
{
463-
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
464-
"type": "object",
465-
"required": [
466-
"both"
467-
],
468-
"properties": {
469-
"both": {
470-
"type": "object",
471-
"required": [
472-
"block",
473-
"timestamp"
474-
],
475-
"properties": {
476-
"block": {
477-
"$ref": "#/definitions/IbcTimeoutBlock"
478-
},
479-
"timestamp": {
480-
"$ref": "#/definitions/Timestamp"
481-
}
482-
}
447+
"timestamp": {
448+
"anyOf": [
449+
{
450+
"$ref": "#/definitions/Timestamp"
451+
},
452+
{
453+
"type": "null"
483454
}
484-
},
485-
"additionalProperties": false
455+
]
486456
}
487-
]
457+
}
488458
},
489459
"IbcTimeoutBlock": {
490460
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",

0 commit comments

Comments
 (0)