Skip to content

Commit

Permalink
Merge pull request #47 from make-software/hotfix/fix_data_type_empty_…
Browse files Browse the repository at this point in the history
…states

Fix empty states for the RPC data params
  • Loading branch information
koltsov-iv authored Sep 4, 2023
2 parents e911f9d + 083cddd commit b7e45a1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
12 changes: 6 additions & 6 deletions rpc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ type ParamQueryGlobalState struct {
}

type ParamQueryGlobalStateID struct {
StateRootHash string `json:"StateRootHash,omitempty"`
BlockHash string `json:"BlockHash,omitempty"`
BlockHeight uint64 `json:"BlockHeight,omitempty"`
StateRootHash string `json:"StateRootHash,omitempty"`
BlockHash string `json:"BlockHash,omitempty"`
BlockHeight *uint64 `json:"BlockHeight,omitempty"`
}

func NewQueryGlobalStateParam(key string, path []string, id ParamQueryGlobalStateID) ParamQueryGlobalState {
Expand All @@ -101,16 +101,16 @@ type PutDeployRequest struct {
}

type BlockIdentifier struct {
Hash string `json:"Hash,omitempty"`
Height uint64 `json:"Height,omitempty"`
Hash string `json:"Hash,omitempty"`
Height *uint64 `json:"Height,omitempty"`
}

type ParamBlockIdentifier struct {
BlockIdentifier BlockIdentifier `json:"block_identifier"`
}

func NewParamBlockByHeight(height uint64) ParamBlockIdentifier {
return ParamBlockIdentifier{BlockIdentifier: BlockIdentifier{Height: height}}
return ParamBlockIdentifier{BlockIdentifier: BlockIdentifier{Height: &height}}
}

func NewParamBlockByHash(hash string) ParamBlockIdentifier {
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *client) QueryGlobalStateByBlockHash(ctx context.Context, blockHash, key
func (c *client) QueryGlobalStateByBlockHeight(ctx context.Context, blockHeight uint64, key string, path []string) (QueryGlobalStateResult, error) {
var result QueryGlobalStateResult
return result, c.processRequest(ctx, MethodQueryGlobalState, NewQueryGlobalStateParam(key, path, ParamQueryGlobalStateID{
BlockHeight: blockHeight,
BlockHeight: &blockHeight,
}), &result)
}

Expand Down
10 changes: 10 additions & 0 deletions tests/data/transfer/transfer_empty_receiver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"deploy_hash": "79e0a49d2c7362f3e00266b8afaf92a5adc1b415288343b2f8871643b505adad",
"from": "account-hash-1cc84cf8cbd9fb0fb6b221680f4655308346031a423b5f0c93a06a29b2c02a2d",
"to": null,
"source": "uref-55ddbc06d7a498dfb9f6e3644e92adc53dfaf8b06f6d851489a07655270811d1-007",
"target": "uref-c98e751d7cd98a70837f1a26105bdba8f7e56ec64fffcc695c8869eb40f74577-007",
"amount": "309258139422",
"gas": "0",
"id": 123123
}
7 changes: 7 additions & 0 deletions tests/rpc/rep_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ func Test_UnmarshalRpcRequest_withoutID(t *testing.T) {
require.NoError(t, err)
assert.JSONEq(t, data, string(result))
}

func Test_NewParamBlockByHeight_withZero(t *testing.T) {
tmp := rpc.NewParamBlockByHeight(0)
res, err := json.Marshal(tmp)
require.NoError(t, err)
assert.JSONEq(t, `{"block_identifier":{"Height":0}}`, string(res))
}
13 changes: 13 additions & 0 deletions tests/types/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ func Test_Transfer_MarshalUnmarshal_ShouldReturnSameResult(t *testing.T) {
assert.NoError(t, err)
assert.JSONEq(t, string(fixture), string(result))
}

func Test_Transfer_WithEmptyReceiver_ShouldReturnSameResult(t *testing.T) {
fixture, err := os.ReadFile("../data/transfer/transfer_empty_receiver.json")
assert.NoError(t, err)

var transfer types.Transfer
err = json.Unmarshal(fixture, &transfer)
assert.NoError(t, err)

result, err := json.Marshal(transfer)
assert.NoError(t, err)
assert.JSONEq(t, string(fixture), string(result))
}
2 changes: 1 addition & 1 deletion types/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ type Transfer struct {
// Target purse
Target key.URef `json:"target"`
// Account to which funds are transferred
To key.AccountHash `json:"to"`
To *key.AccountHash `json:"to"`
}

0 comments on commit b7e45a1

Please sign in to comment.