diff --git a/testing/demo/main.go b/testing/demo/main.go deleted file mode 100644 index edab4f4..0000000 --- a/testing/demo/main.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "github.com/celestiaorg/celestia-zkevm-ibc-demo/testing/demo/pkg" - "github.com/hashicorp/go-multierror" - "github.com/spf13/cobra" -) - -var rootCmd = &cobra.Command{ - Use: "demo", - Short: "Runs the full ZK IBC demo", - Long: `Runs the full ZK IBC demo, using docker-compose to run a ZK enabled Cosmos chain, a Reth Rollup -connected to Celestia. It deploys the IBC smart contracts, establishes a connection between the rollup and chain, -and performs a token transfer`, - RunE: func(cmd *cobra.Command, args []string) (err error) { - if err := pkg.Start(cmd.Context()); err != nil { - return err - } - defer func() { - stopErr := pkg.Stop(context.Background()) - if stopErr != nil { - err = multierror.Append(err, stopErr) - } - }() - if err := pkg.DeployContracts(); err != nil { - return err - } - if err := pkg.EstablishIBCConnection(); err != nil { - return err - } - return pkg.Transfer() - }, -} - -var startCmd = &cobra.Command{ - Use: "start", - Short: "Start the demo environment", - RunE: func(cmd *cobra.Command, args []string) error { - return pkg.Start(cmd.Context()) - }, -} - -var setupIBCContractsCmd = &cobra.Command{ - Use: "setup-ibc-contracts", - Short: "Setup IBC contracts", - RunE: func(cmd *cobra.Command, args []string) error { - return pkg.DeployContracts() - }, -} - -var createIBCConnectionCmd = &cobra.Command{ - Use: "create-ibc-connection", - Short: "Create IBC connection between chains", - RunE: func(cmd *cobra.Command, args []string) error { - return pkg.EstablishIBCConnection() - }, -} - -var transferCmd = &cobra.Command{ - Use: "transfer", - Short: "Transfer tokens over IBC", - RunE: func(cmd *cobra.Command, args []string) error { - return pkg.Transfer() - }, -} - -var stopCmd = &cobra.Command{ - Use: "stop", - Short: "Stops and cleans up the demo environment", - RunE: func(cmd *cobra.Command, args []string) error { - return pkg.Stop(cmd.Context()) - }, -} - -func init() { - rootCmd.AddCommand(startCmd) - rootCmd.AddCommand(setupIBCContractsCmd) - rootCmd.AddCommand(createIBCConnectionCmd) - rootCmd.AddCommand(transferCmd) - rootCmd.AddCommand(stopCmd) -} - -func main() { - if err := rootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/testing/demo/pkg/connect.go b/testing/demo/pkg/connect.go deleted file mode 100644 index f7f83f3..0000000 --- a/testing/demo/pkg/connect.go +++ /dev/null @@ -1,89 +0,0 @@ -package pkg - -import ( - "context" - "fmt" - "math/big" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethclient" - hdwallet "github.com/miguelmota/go-ethereum-hdwallet" -) - -func EstablishIBCConnection() error { - // Connect to local geth node - client, err := ethclient.Dial("http://localhost:8545") - if err != nil { - return fmt.Errorf("failed to connect to ethereum client: %v", err) - } - - // Create wallet from mnemonic - mnemonic := "swallow practice city pear alert scale endless service rather clever salmon toss tenant law antenna garage order helmet host disorder innocent proof crunch length" - wallet, err := hdwallet.NewFromMnemonic(mnemonic) - if err != nil { - return fmt.Errorf("failed to create wallet: %v", err) - } - - // Derive account - path := hdwallet.MustParseDerivationPath("m/44'/60'/0'/0/0") - account, err := wallet.Derive(path, true) - if err != nil { - return fmt.Errorf("failed to derive account: %v", err) - } - - // Get private key - privateKey, err := wallet.PrivateKey(account) - if err != nil { - return fmt.Errorf("failed to get private key: %v", err) - } - - publicKey, err := wallet.PublicKey(account) - if err != nil { - return fmt.Errorf("failed to get public key: %v", err) - } - - address := crypto.PubkeyToAddress(*publicKey) - fmt.Printf("Address: %s\n", address.Hex()) - - // Create transaction - nonce, err := client.PendingNonceAt(context.Background(), account.Address) - if err != nil { - return fmt.Errorf("failed to get nonce: %v", err) - } - - gasPrice, err := client.SuggestGasPrice(context.Background()) - if err != nil { - return fmt.Errorf("failed to get gas price: %v", err) - } - - toAddress := common.HexToAddress("0x742d35Cc6634C0532925a3b844Bc454e4438f44e") - value := big.NewInt(1000000000000000000) // 1 ETH - - tx := types.NewTx(&types.LegacyTx{ - Nonce: nonce, - To: &toAddress, - Value: value, - Gas: 21000, - GasPrice: gasPrice, - }) - - chainID, err := client.NetworkID(context.Background()) - if err != nil { - return fmt.Errorf("failed to get chain id: %v", err) - } - - signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey) - if err != nil { - return fmt.Errorf("failed to sign transaction: %v", err) - } - - err = client.SendTransaction(context.Background(), signedTx) - if err != nil { - return fmt.Errorf("failed to send transaction: %v", err) - } - - fmt.Printf("Transaction sent: %s\n", signedTx.Hash().Hex()) - return nil -} diff --git a/testing/demo/pkg/deploy_contracts.go b/testing/demo/pkg/deploy_contracts.go deleted file mode 100644 index 9092729..0000000 --- a/testing/demo/pkg/deploy_contracts.go +++ /dev/null @@ -1,25 +0,0 @@ -package pkg - -import ( - "fmt" - "os/exec" -) - -func DeployContracts() error { - fmt.Println("Deploying IBC smart contracts...") - - // Define the deployment command - cmd := exec.Command("forge", "script", "E2ETestDeploy.s.sol:E2ETestDeploy", "--rpc-url", "http://localhost:8545", "--private-key", "0x82bfcfadbf1712f6550d8d2c00a39f05b33ec78939d0167be2a737d691f33a6a", "--broadcast") - - // Set the working directory - cmd.Dir = "./solidity-ibc-eureka/scripts" - - // Run the command and capture the output - output, err := cmd.CombinedOutput() - if err != nil { - return fmt.Errorf("failed to deploy contracts: %v\nOutput: %s", err, string(output)) - } - - fmt.Println(string(output)) - return nil -} diff --git a/testing/demo/pkg/establish_transfer_channels.go b/testing/demo/pkg/establish_transfer_channels.go deleted file mode 100644 index 05f127b..0000000 --- a/testing/demo/pkg/establish_transfer_channels.go +++ /dev/null @@ -1,6 +0,0 @@ -package pkg - -// func EstablishChannels() error { -// BroadcastMessages() -// return nil -// } diff --git a/testing/demo/pkg/start.go b/testing/demo/pkg/start.go deleted file mode 100644 index 9474d22..0000000 --- a/testing/demo/pkg/start.go +++ /dev/null @@ -1,74 +0,0 @@ -package pkg - -import ( - "context" - "fmt" - "log" - "time" - - client "github.com/celestiaorg/celestia-openrpc" -) - -func Start(ctx context.Context) error { - fmt.Println("Starting demo environment...") - - errCh := make(chan error) - go func() { - if err := runDockerCompose(ctx, "up"); err != nil { - errCh <- err - } - }() - - select { - case err := <-errCh: - return err - case <-ctx.Done(): - return ctx.Err() - case <-time.After(10 * time.Second): - go func() { - select { - case err := <-errCh: - log.Println("error running docker compose up:", err) - case <-ctx.Done(): - return - } - }() - } - - if err := waitForDA(ctx, 3, time.Minute); err != nil { - return err - } - - return nil -} - -func waitForDA(ctx context.Context, height uint64, timeout time.Duration) error { - client, err := client.NewClient(ctx, "http://localhost:26658", "") - if err != nil { - return fmt.Errorf("failed to create celestia DA client: %w", err) - } - - var latestHeight uint64 - ticker := time.NewTicker(1 * time.Second) - defer ticker.Stop() - timeoutTimer := time.NewTimer(timeout) - defer timeoutTimer.Stop() - for { - select { - case <-timeoutTimer.C: - return fmt.Errorf("timeout waiting for DA height %d (latest: %d)", height, latestHeight) - case <-ctx.Done(): - return ctx.Err() - case <-ticker.C: - header, err := client.Header.NetworkHead(ctx) - if err != nil { - return err - } - latestHeight = header.Height() - if latestHeight >= height { - return nil - } - - } - } -} diff --git a/testing/demo/pkg/stop.go b/testing/demo/pkg/stop.go deleted file mode 100644 index 3904af0..0000000 --- a/testing/demo/pkg/stop.go +++ /dev/null @@ -1,22 +0,0 @@ -package pkg - -import ( - "context" - "fmt" - "os" - "os/exec" -) - -func Stop(ctx context.Context) error { - fmt.Println("Stopping demo environment...") - if err := runDockerCompose(ctx, "rm", "-s", "-f"); err != nil { - return err - } - - return os.RemoveAll("./.tmp") -} - -func runDockerCompose(ctx context.Context, args ...string) error { - args = append([]string{"compose"}, args...) - return exec.CommandContext(ctx, "docker", args...).Run() -} diff --git a/testing/demo/pkg/transfer.go b/testing/demo/pkg/transfer.go deleted file mode 100644 index a477c32..0000000 --- a/testing/demo/pkg/transfer.go +++ /dev/null @@ -1,8 +0,0 @@ -package pkg - -import "fmt" - -func Transfer() error { - fmt.Println("Transferring tokens...") - return nil -}