Skip to content

Commit

Permalink
Fix rentepoch overflow (#178)
Browse files Browse the repository at this point in the history
* Fix overflow of Account.RentEpoch

* Update test

* Update the test to verify the change
  • Loading branch information
carlcarl committed Mar 22, 2024
1 parent 790032b commit 242d699
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/base64"
stdjson "encoding/json"
"fmt"
"math/big"
"testing"

"github.com/AlekSi/pointer"
Expand All @@ -34,7 +35,7 @@ import (
)

func TestClient_GetAccountInfo(t *testing.T) {
responseBody := `{"context":{"slot":83986105},"value":{"data":["dGVzdA==","base64"],"executable":true,"lamports":999999,"owner":"11111111111111111111111111111111","rentEpoch":207}}`
responseBody := `{"context":{"slot":83986105},"value":{"data":["dGVzdA==","base64"],"executable":true,"lamports":999999,"owner":"11111111111111111111111111111111","rentEpoch":18446744073709551615}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
Expand Down Expand Up @@ -64,6 +65,7 @@ func TestClient_GetAccountInfo(t *testing.T) {
reqBody,
)

rentEpoch, _ := new(big.Int).SetString("18446744073709551615", 10)
assert.Equal(t,
&GetAccountInfoResult{
RPCContext: RPCContext{
Expand All @@ -80,7 +82,7 @@ func TestClient_GetAccountInfo(t *testing.T) {
},
},
Executable: true,
RentEpoch: 207,
RentEpoch: rentEpoch,
},
}, out)
}
Expand Down Expand Up @@ -1691,7 +1693,7 @@ func TestClient_GetMultipleAccounts(t *testing.T) {
rawDataEncoding: solana.EncodingBase64,
},
Executable: true,
RentEpoch: 207,
RentEpoch: big.NewInt(207),
},
},
}
Expand Down Expand Up @@ -1781,7 +1783,7 @@ func TestClient_GetProgramAccounts(t *testing.T) {
rawDataEncoding: solana.EncodingBase64,
},
Executable: true,
RentEpoch: 206,
RentEpoch: big.NewInt(206),
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/base64"
stdjson "encoding/json"
"fmt"
"math/big"

bin "github.com/gagliardetto/binary"

Expand Down Expand Up @@ -294,7 +295,7 @@ type Account struct {
Executable bool `json:"executable"`

// The epoch at which this account will next owe rent
RentEpoch uint64 `json:"rentEpoch"`
RentEpoch *big.Int `json:"rentEpoch"`
}

type DataBytesOrJSON struct {
Expand Down

0 comments on commit 242d699

Please sign in to comment.