Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit ae86f69

Browse files
fix: uses of copy (#62)
Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl>
1 parent 18a0a59 commit ae86f69

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

proxy/grpc/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (c *Client) InitChain(ctx context.Context, genesisTime time.Time, initialHe
6161
return types.Hash{}, 0, err
6262
}
6363

64-
var stateRoot types.Hash
64+
stateRoot := make([]byte, len(resp.StateRoot))
6565
copy(stateRoot[:], resp.StateRoot)
6666

6767
return stateRoot, resp.MaxBytes, nil
@@ -99,7 +99,7 @@ func (c *Client) ExecuteTxs(ctx context.Context, txs []types.Tx, blockHeight uin
9999
return types.Hash{}, 0, err
100100
}
101101

102-
var updatedStateRoot types.Hash
102+
updatedStateRoot := make([]byte, len(resp.UpdatedStateRoot))
103103
copy(updatedStateRoot[:], resp.UpdatedStateRoot)
104104

105105
return updatedStateRoot, resp.MaxBytes, nil

proxy/grpc/client_server_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ func TestClientServer(t *testing.T) {
5656
chainID := "test-chain"
5757

5858
// initialize a new Hash with a fixed size
59-
expectedStateRoot := make([]byte, 32)
59+
expectedStateRoot := types.Hash(make([]byte, 32))
6060
copy(expectedStateRoot, []byte{1, 2, 3})
61-
var stateRootHash types.Hash
61+
stateRootHash := types.Hash(make([]byte, 32))
6262
copy(stateRootHash[:], expectedStateRoot)
63+
assert.Equal(t, expectedStateRoot, stateRootHash[:])
6364

6465
expectedMaxBytes := uint64(1000000)
6566

proxy/grpc/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *Server) ExecuteTxs(ctx context.Context, req *pb.ExecuteTxsRequest) (*pb
8383
txs[i] = tx
8484
}
8585

86-
var prevStateRoot types.Hash
86+
prevStateRoot := make([]byte, len(req.PrevStateRoot))
8787
copy(prevStateRoot[:], req.PrevStateRoot)
8888

8989
updatedStateRoot, maxBytes, err := s.exec.ExecuteTxs(

0 commit comments

Comments
 (0)