Skip to content

Commit

Permalink
chore: Update SyncStatus struct to use pointer for SyncStatus field
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Sep 2, 2024
1 parent 83ab9a3 commit 9adb94f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rpc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (provider *Provider) Syncing(ctx context.Context) (*SyncStatus, error) {
}
switch res := result.(type) {
case bool:
return &SyncStatus{SyncStatus: res}, nil
return &SyncStatus{SyncStatus: &res}, nil
case SyncStatus:
return &res, nil
default:
Expand Down
18 changes: 9 additions & 9 deletions rpc/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ func TestSyncing(t *testing.T) {
continue
}

require.False(t, sync.SyncStatus)
if sync.StartingBlockHash == nil {
require.Zero(t, sync.StartingBlockHash)
require.Zero(t, sync.StartingBlockNum)
require.Zero(t, sync.CurrentBlockHash)
require.Zero(t, sync.CurrentBlockNum)
require.Zero(t, sync.HighestBlockHash)
require.Zero(t, sync.HighestBlockNum)
} else {
if sync.SyncStatus == nil {
require.True(t, strings.HasPrefix(sync.CurrentBlockHash.String(), "0x"), "current block hash should return a string starting with 0x")
require.NotZero(t, sync.StartingBlockHash)
require.NotZero(t, sync.StartingBlockNum)
require.NotZero(t, sync.CurrentBlockHash)
require.NotZero(t, sync.CurrentBlockNum)
require.NotZero(t, sync.HighestBlockHash)
require.NotZero(t, sync.HighestBlockNum)
} else {
require.False(t, *sync.SyncStatus)
require.Zero(t, sync.StartingBlockHash)
require.Zero(t, sync.StartingBlockNum)
require.Zero(t, sync.CurrentBlockHash)
require.Zero(t, sync.CurrentBlockNum)
require.Zero(t, sync.HighestBlockHash)
require.Zero(t, sync.HighestBlockNum)
}

}
Expand Down
4 changes: 2 additions & 2 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type PendingStateUpdate struct {

// SyncStatus is An object describing the node synchronization status
type SyncStatus struct {
SyncStatus bool
SyncStatus *bool
StartingBlockHash *felt.Felt `json:"starting_block_hash,omitempty"`
StartingBlockNum NumAsHex `json:"starting_block_num,omitempty"`
CurrentBlockHash *felt.Felt `json:"current_block_hash,omitempty"`
Expand All @@ -122,7 +122,7 @@ type SyncStatus struct {
// - []byte: the JSON encoding of the SyncStatus struct
// - error: any error that occurred during the marshaling process
func (s SyncStatus) MarshalJSON() ([]byte, error) {
if !s.SyncStatus {
if !*s.SyncStatus {
return []byte("false"), nil
}
output := map[string]interface{}{}
Expand Down

0 comments on commit 9adb94f

Please # to comment.