-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
382 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "devnet", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.devnet.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package main | ||
|
||
import "github.com/cartesi/rollups-node/devnet/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package docker | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cartesi/rollups-node/internal/logger" | ||
) | ||
|
||
func setup() { | ||
logger.Init("warning", false) | ||
} | ||
func TestSimpleService(t *testing.T) { | ||
|
||
t.Run("it stops when the context is cancelled", func(t *testing.T) { | ||
setup() | ||
container, cerr := CreateDockerContainer("docker.io/cartesi/anvil:devel", nil, "") | ||
if cerr != nil { | ||
t.Logf("Error creating container: %v", cerr) | ||
t.FailNow() | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
exit := make(chan error) | ||
|
||
go func() { | ||
if err := container.Start(ctx); err != nil { | ||
exit <- err | ||
} | ||
}() | ||
|
||
<-time.After(50000 * time.Millisecond) | ||
cancel() | ||
|
||
err := <-exit | ||
exitError, ok := err.(*exec.ExitError) | ||
if !ok || !assertExitErrorWasCausedBy(exitError, syscall.SIGTERM) { | ||
t.Logf("service exited for the wrong reason: %v", err) | ||
t.FailNow() | ||
} | ||
}) | ||
} | ||
|
||
func assertExitErrorWasCausedBy(err *exec.ExitError, signal syscall.Signal) bool { | ||
status := err.Sys().(syscall.WaitStatus) | ||
return status.Signal() == signal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env sh | ||
|
||
# dump the state from the JSON-RPC server, convert from the hex anvil returns to text, which is a JSON string | ||
curl \ | ||
-sL \ | ||
-X POST \ | ||
-H 'Content-Type: application/json' \ | ||
--data '{"id":1,"jsonrpc":"2.0","method":"anvil_dumpState","params":[]}' "${RPC_URL:-http://127.0.0.1:8545}" | \ | ||
jq -r .result| \ | ||
cut -c 3- | \ | ||
xxd -r -p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
# https://ethereum.org/en/developers/docs/apis/json-rpc/#net_listening | ||
curl -X POST -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"net_listening","params":[]}' ${RPC_URL:-http://127.0.0.1:8545} | jq '.result' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
RPC_URL="${RPC_URL:-http://127.0.0.1:8545}" | ||
|
||
# use a large column value so we have everything on one line, even though man says 256 is the maximum | ||
STATE=$(xxd -ps -c 1000000000) | ||
|
||
# build the JSON-RPC request, and write to a file because it's too long for the curl call | ||
DATA="{\"id\":2,\"jsonrpc\":\"2.0\",\"method\":\"anvil_loadState\",\"params\":[\"0x$STATE\"]}" | ||
TMPFILE=$(mktemp) | ||
echo "$DATA" > "$TMPFILE" | ||
|
||
echo "Loading state into ${RPC}" | ||
curl -sL -H 'Content-Type: application/json' -d @"$TMPFILE" "$RPC_URL" | jq -r .result |