Skip to content
4 changes: 2 additions & 2 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/common"
)

func AdaptBlock(response *starknet.Block, sig *starknet.Signature) (*core.Block, error) {
func AdaptBlock(response *starknet.Block, sig []*felt.Felt) (*core.Block, error) {
if response == nil {
return nil, errors.New("nil client block")
}
Expand All @@ -37,7 +37,7 @@ func AdaptBlock(response *starknet.Block, sig *starknet.Signature) (*core.Block,

sigs := [][]*felt.Felt{}
if sig != nil {
sigs = append(sigs, sig.Signature)
sigs = append(sigs, sig)
}

return &core.Block{
Expand Down
7 changes: 6 additions & 1 deletion adapters/sn2core/sn2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ func TestAdaptBlock(t *testing.T) {

response, err := client.Block(ctx, strconv.FormatUint(test.number, 10))
require.NoError(t, err)
block, err := sn2core.AdaptBlock(response, test.sig)

var sig []*felt.Felt
if test.sig != nil {
sig = test.sig.Signature
}
block, err := sn2core.AdaptBlock(response, sig)
require.NoError(t, err)

expectedEventCount := uint64(0)
Expand Down
12 changes: 9 additions & 3 deletions clients/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"
"net/http"
"strconv"
"sync/atomic"
"time"

Expand Down Expand Up @@ -382,10 +383,15 @@ func (c *Client) Signature(ctx context.Context, blockID string) (*starknet.Signa
return signature, nil
}

func (c *Client) StateUpdateWithBlock(ctx context.Context, blockID string) (*starknet.StateUpdateWithBlock, error) {
func (c *Client) StateUpdateWithBlock(
ctx context.Context,
blockID string,
includeSignature bool,
) (*starknet.StateUpdateWithBlock, error) {
queryURL := c.buildQueryString("get_state_update", map[string]string{
blockNumberArg: blockID,
"includeBlock": "true",
blockNumberArg: blockID,
"includeBlock": "true",
"includeSignature": strconv.FormatBool(includeSignature),
})

body, err := c.get(ctx, queryURL)
Expand Down
23 changes: 21 additions & 2 deletions clients/feeder/feeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ func TestStateUpdateWithBlock(t *testing.T) {
client := feeder.NewTestClient(t, &networks.Integration)

t.Run("Test normal case", func(t *testing.T) {
actualStateUpdate, err := client.StateUpdateWithBlock(t.Context(), strconv.Itoa(0))
actualStateUpdate, err := client.StateUpdateWithBlock(t.Context(), strconv.Itoa(0), false)
assert.NoError(t, err)
assert.Equal(
t,
Expand All @@ -1038,16 +1038,35 @@ func TestStateUpdateWithBlock(t *testing.T) {
assert.Empty(t, actualStateUpdate.StateUpdate.StateDiff.Nonces)
assert.Empty(t, actualStateUpdate.StateUpdate.StateDiff.DeclaredClasses)
})
t.Run("Test with includeSignature", func(t *testing.T) {
actualStateUpdate, err := client.StateUpdateWithBlock(t.Context(), strconv.Itoa(78541), true)
assert.NoError(t, err)
assert.NotEmpty(t, actualStateUpdate.StateUpdate)
assert.NotEmpty(t, actualStateUpdate.Block)
assert.NotEmpty(t, actualStateUpdate.Signature)
assert.Equal(t, 2, len(actualStateUpdate.Signature))
assert.Equal(
t,
"0xe59046f297679492dec6987bf580707fc7a438bd3da98b9c73a6e495d915d",
actualStateUpdate.Signature[0].String(),
)
assert.Equal(
t,
"0x23e7e5fddc5e6be25f264e8571f98948600be4768a9f6ab7406ef1ef3da43c3",
actualStateUpdate.Signature[1].String(),
)
})
t.Run("Test on unexisting block", func(t *testing.T) {
actualStateUpdate, err := client.StateUpdateWithBlock(
t.Context(),
strconv.Itoa(10000000000),
false,
)
assert.Error(t, err)
assert.Nil(t, actualStateUpdate)
})
t.Run("Test on latest block", func(t *testing.T) {
actualStateUpdate, err := client.StateUpdateWithBlock(t.Context(), "latest")
actualStateUpdate, err := client.StateUpdateWithBlock(t.Context(), "latest", false)
assert.NoError(t, err)
assert.NotNil(t, actualStateUpdate)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x4ad6fcb4adc8f45ab532267a878cade0e576300fbd1bfcafac48c9b367ed53d",
"0x54d3cd3d76a3a1db3b8d4a934a5c15d4ca3de771146675f744b471104d5d138"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x7fe660044180e7d436e77ab017faff0686c0b02a425ade81de8fd5aa95663bb",
"0xc475f270d1e6d735829ac7db0c7580f86b8f788e44106220312125496d1931"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,9 @@
],
"replaced_classes": []
}
}
},
"signature": [
"0x405a7a6641a0c5990db264b67676e6bde816716be5665790bb314c80ca9f5f0",
"0x2665b141b14b80a3f96d7487665b49dba53d2a873a8d45561bfefd9499ca10a"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1347,5 +1347,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0xe59046f297679492dec6987bf580707fc7a438bd3da98b9c73a6e495d915d",
"0x23e7e5fddc5e6be25f264e8571f98948600be4768a9f6ab7406ef1ef3da43c3"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -760,5 +760,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x484a36b518e33198bfe7a29d82842ae092f9181120e1d49b926c651adf315ed",
"0x7e21090ab0c6c70fa2b73e17e6288db298dbe191b04bfd1721436530e84861e"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x5c328d673c07e530a45d6f12e569df0d059d97bf920d978e44daa54fb3db655",
"0x37feba468c96099a9a610c34bab6230af8c7e9d78c1ddb7436488961fc5161d"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x2fb6fa73bf46ede7240e5034d8ce28ef63e90b3475f476d1ebb89bf3da04725",
"0x46e54ef8121fb3a69989329cbe993602534ff27c7330a4d92bcfc697cac5678"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x4009f6bce4d9c392b031dd335777dd4b425b3c1da9d82b9b2a4aec3b7b77fd4",
"0x654baea62f7d9f90cdcb1623428b7f437eb45aa880c5c628c6ba77aa9370ee"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1335,5 +1335,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
}
},
"signature": [
"0x6c760ac701b4d13810fb31f513518ce9a2dcd8cf33e60d688b30876e93ca3f5",
"0x10c44d9764842557f1eb8e98a870710ac8a6e15928e67b7fb5f520861d5c0b0"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11481,5 +11481,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x7ee8a86cd921053e037181b4b57b813db63b88ad5a5975ecada151d079322ae",
"0x6f97aefb8f14351f8a60f66c936ab8175744217522d7b335deadae8a4f15c68"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
}
},
"signature": [
"0x30a199364f1cec47d386da1839015413a464456ca6d63d6f45156d0a1254356",
"0x784aba6f4948a6a1caa4f7247adcabdfe41a8ec21668c30621cd9d265516dc6"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@
"declared_classes": [],
"replaced_classes": []
}
}
}
},
"signature": [
"0x47fe7aea2435f8be68f0dce8f859f0f2f31db43eddc9269a200ef7a530e34a0",
"0x636260cd4a8a9991a9a2f7b09a4d8ebdfbfdb7d32d0a2b8e23d8ebc0ae014dc"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
}
},
"signature": [
"0x711dcda18cd159c7372ab2d82d15534ea42d1e2317fc93426506daf492755b0",
"0x3898b1c5e8d76243b608e767981f1fd50ed894cbd7d85afdc1c108f76bdfc10"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7141,5 +7141,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x27901a327fc1b9990874ed5d06f16f02440b6a1ef605e13943f9fb32743faa8",
"0x186003cc2cea1204343e62bc160ec3ac5ea6eb563d487f87a866ec0f477b57e"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9418,5 +9418,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x1847649e0ee0e556f130034d32fdcdff7aa0131a77c9f644f5fda7bc17365d7",
"0x2e9dd9a40897a40038c7f34328c4d1eb9aadd0c8c861b88d2bc840e092444e4"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7629,5 +7629,9 @@
"migrated_compiled_classes": [],
"replaced_classes": []
}
}
},
"signature": [
"0x36e42e560b5ceb08058c61f647cd588b64e6ef45b80ff6ec38253ed7edd2c53",
"0x601931568533df6b870573c1fd76eab74c7e8f9c7b260361b6e84cd85a70630"
]
}
6 changes: 5 additions & 1 deletion consensus/p2p/validator/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func BuildTestFixture(
client := feeder.NewTestClient(t, testCase.Network)
gw := adaptfeeder.New(client)

rawStateUpdate, err := client.StateUpdateWithBlock(t.Context(), fmt.Sprintf("%d", testCase.Height))
rawStateUpdate, err := client.StateUpdateWithBlock(
t.Context(),
fmt.Sprintf("%d", testCase.Height),
false,
)
require.NoError(t, err)

stateUpdate, block, err := gw.StateUpdateWithBlock(t.Context(), uint64(testCase.Height))
Expand Down
4 changes: 2 additions & 2 deletions rpc/v10/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3258,15 +3258,15 @@ func GetTestBlockWithCommitments(
t.Helper()

blockID := strconv.FormatUint(blockNumber, 10)
blockWithStateUpdate, err := client.StateUpdateWithBlock(t.Context(), blockID)
blockWithStateUpdate, err := client.StateUpdateWithBlock(t.Context(), blockID, false)
require.NoError(t, err)

sig, err := client.Signature(t.Context(), blockID)
require.NoError(t, err)

adaptedState, err := sn2core.AdaptStateUpdate(blockWithStateUpdate.StateUpdate)
require.NoError(t, err)
adaptedBlock, err := sn2core.AdaptBlock(blockWithStateUpdate.Block, sig)
adaptedBlock, err := sn2core.AdaptBlock(blockWithStateUpdate.Block, sig.Signature)
require.NoError(t, err)

commitments := &core.BlockCommitments{
Expand Down
9 changes: 7 additions & 2 deletions starknet/state_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ type StateDiff struct {
} `json:"migrated_compiled_classes"`
}

// StateUpdateWithBlock object returned by the feeder in JSON format for "get_state_update" endpoint with includingBlock arg
// StateUpdateWithBlock represents the object response by the feeder for "get_state_update"
// endpoint with `includeBlock` and `includeSignature` arguments
type StateUpdateWithBlock struct {
Block *Block `json:"block"`
StateUpdate *StateUpdate `json:"state_update"`

// Only present if `includeBlock` argument is set to `true`
Block *Block `json:"block"`
// Only present if `includeSignature` argument is set to `true`
Signature []*felt.Felt `json:"signature"`
}
Loading
Loading