Skip to content

Commit

Permalink
CSDK/fixed_info_get_status_response
Browse files Browse the repository at this point in the history
Fixed info_get_status response parsing
  • Loading branch information
ZhmakAS committed Jan 16, 2025
1 parent b521e48 commit 36e415a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
16 changes: 12 additions & 4 deletions rpc/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,22 @@ type InfoGetStatusResult struct {
High uint64 `json:"high"`
} `json:"available_block_range"`
// Indicating the state of the block synchronizer component
BlockSync struct {
Historical string `json:"historical,omitempty"`
Forward string `json:"forward,omitempty"`
} `json:"block_sync"`
BlockSync BlockSynchronizerStatus `json:"block_sync"`

rawJSON json.RawMessage
}

type BlockSynchronizerStatus struct {
Historical *BlockSyncStatus `json:"historical,omitempty"`
Forward *BlockSyncStatus `json:"forward,omitempty"`
}

type BlockSyncStatus struct {
BlockHash key.Hash `json:"block_hash"`
BlockHeight *uint64 `json:"block_height,omitempty"`
AcquisitionState string `json:"acquisition_state"`
}

// NodeNextUpgrade contains the information about the next protocol upgrade.
type NodeNextUpgrade struct {
//The first era to which the associated protocol version applies.
Expand Down
14 changes: 11 additions & 3 deletions tests/data/rpc_response/get_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@
"high": 170022
},
"block_sync": {
"historical": null,
"forward": null
"historical": {
"block_hash": "16ddf28e2b3d2e17f4cef36f8b58827eca917af225d139b0c77df3b4a67dc55e",
"block_height": 40,
"acquisition_state": "have strict finality(40) for: block hash 16dd..c55e"
},
"forward": {
"block_hash": "59907b1e32a9158169c4d89d9ce5ac9164fc31240bfcfb0969227ece06d74983",
"block_height": 6701,
"acquisition_state": "have block body(6701) for: block hash 5990..4983"
}
},
"latest_switch_block_hash": "099cc3232b04ebb556c73328597c0b8c518fa4565c7d1f7981bc251414ce8c2f"
}
}
}
8 changes: 8 additions & 0 deletions tests/rpc/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,14 @@ func Test_DefaultClient_GetStatus(t *testing.T) {
require.NoError(t, err)
assert.NotEmpty(t, result.ChainSpecName)
assert.NotEmpty(t, result.LatestSwitchBlockHash)
assert.NotNil(t, result.BlockSync.Forward)
assert.NotEmpty(t, result.BlockSync.Forward.BlockHash)
assert.NotEmpty(t, result.BlockSync.Forward.AcquisitionState)
assert.NotNil(t, result.BlockSync.Forward.BlockHeight)
assert.NotNil(t, result.BlockSync.Historical)
assert.NotEmpty(t, result.BlockSync.Historical.BlockHash)
assert.NotEmpty(t, result.BlockSync.Historical.AcquisitionState)
assert.NotNil(t, result.BlockSync.Historical.BlockHeight)
}

func Test_DefaultClient_GetPeers(t *testing.T) {
Expand Down

0 comments on commit 36e415a

Please sign in to comment.