From 9adb94f959114de829fa74c1271fae331f069f4f Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Mon, 2 Sep 2024 00:17:58 -0300 Subject: [PATCH] chore: Update SyncStatus struct to use pointer for SyncStatus field --- rpc/chain.go | 2 +- rpc/chain_test.go | 18 +++++++++--------- rpc/types.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rpc/chain.go b/rpc/chain.go index 743eedf0..2f440290 100644 --- a/rpc/chain.go +++ b/rpc/chain.go @@ -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: diff --git a/rpc/chain_test.go b/rpc/chain_test.go index 92faceea..e460124c 100644 --- a/rpc/chain_test.go +++ b/rpc/chain_test.go @@ -87,15 +87,7 @@ 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) @@ -103,6 +95,14 @@ func TestSyncing(t *testing.T) { 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) } } diff --git a/rpc/types.go b/rpc/types.go index 1cbfbb73..4287b281 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -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"` @@ -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{}{}