|
| 1 | +// Copyright 2026 Sonic Operations Ltd |
| 2 | +// This file is part of the Sonic Client |
| 3 | +// |
| 4 | +// Sonic is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Sonic is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with Sonic. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package sonicapi |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/0xsoniclabs/sonic/gossip/blockproc/bundle" |
| 23 | + "github.com/ethereum/go-ethereum/common" |
| 24 | + "github.com/ethereum/go-ethereum/rpc" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | +) |
| 27 | + |
| 28 | +func TestNewRPCExecutionPlan(t *testing.T) { |
| 29 | + plan := bundle.ExecutionPlan{ |
| 30 | + Steps: []bundle.ExecutionStep{ |
| 31 | + { |
| 32 | + From: common.HexToAddress("0x1111111111111111111111111111111111111111"), |
| 33 | + Hash: common.HexToHash("0x2222222222222222222222222222222222222222222222222222222222222222"), |
| 34 | + }, |
| 35 | + { |
| 36 | + From: common.HexToAddress("0x3333333333333333333333333333333333333333"), |
| 37 | + Hash: common.HexToHash("0x4444444444444444444444444444444444444444444444444444444444444444"), |
| 38 | + }, |
| 39 | + }, |
| 40 | + Flags: bundle.EF_TolerateInvalid | bundle.EF_OneOf, |
| 41 | + Range: bundle.BlockRange{ |
| 42 | + Earliest: 100, |
| 43 | + Latest: 200, |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + rpcPlan := NewRPCExecutionPlan(plan) |
| 48 | + |
| 49 | + require.Equal(t, plan.Flags, rpcPlan.Flags) |
| 50 | + require.Equal(t, rpc.BlockNumber(plan.Range.Earliest), rpcPlan.Earliest) |
| 51 | + require.Equal(t, rpc.BlockNumber(plan.Range.Latest), rpcPlan.Latest) |
| 52 | + require.Len(t, rpcPlan.Steps, len(plan.Steps)) |
| 53 | + for i, step := range plan.Steps { |
| 54 | + require.Equal(t, step.From, rpcPlan.Steps[i].From) |
| 55 | + require.Equal(t, step.Hash, rpcPlan.Steps[i].Hash) |
| 56 | + } |
| 57 | +} |
0 commit comments