Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add evmChainID to replay cli #8687

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions core/cmd/blocks_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"net/url"
"strconv"

"github.com/pkg/errors"
Expand All @@ -28,6 +29,11 @@ func initBlocksSubCmds(client *Client) []cli.Command {
Name: "force",
Usage: "Whether to force broadcasting logs which were already consumed and that would otherwise be skipped",
},
cli.Int64Flag{
Name: "evm-chain-id",
Usage: "Chain ID of the EVM-based blockchain",
Required: false,
},
},
},
}
Expand All @@ -40,14 +46,19 @@ func (cli *Client) ReplayFromBlock(c *clipkg.Context) (err error) {
return cli.errorOut(errors.New("Must pass a positive value in '--block-number' parameter"))
}

forceBroadcast := c.Bool("force")
v := url.Values{}
v.Add("force", strconv.FormatBool(c.Bool("force")))

if c.IsSet("evm-chain-id") {
v.Add("evmChainID", fmt.Sprintf("%d", c.Int64("evm-chain-id")))
}

buf := bytes.NewBufferString("{}")
resp, err := cli.HTTP.Post(
fmt.Sprintf(
"/v2/replay_from_block/%v?force=%s",
"/v2/replay_from_block/%v?%s",
blockNumber,
strconv.FormatBool(forceBroadcast),
v.Encode(),
), buf)
if err != nil {
return cli.errorOut(err)
Expand Down
8 changes: 8 additions & 0 deletions core/cmd/remote_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ func TestClient_ReplayBlocks(t *testing.T) {

c := cli.NewContext(nil, set, nil)
assert.NoError(t, client.ReplayFromBlock(c))

require.NoError(t, set.Set("evm-chain-id", "12345678"))
c = cli.NewContext(nil, set, nil)
assert.ErrorContains(t, client.ReplayFromBlock(c), "evmChainID does not match any local chains")

require.NoError(t, set.Set("evm-chain-id", "0"))
c = cli.NewContext(nil, set, nil)
assert.NoError(t, client.ReplayFromBlock(c))
}

func TestClient_CreateExternalInitiator(t *testing.T) {
Expand Down