Skip to content

Commit

Permalink
Merge branch 'main' into fix-preflight-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms authored Sep 8, 2023
2 parents 2647856 + 72d7cf9 commit f8b5d72
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 41 deletions.
67 changes: 67 additions & 0 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package test

import (
"crypto/sha256"
"fmt"
"os"
"os/exec"
"strings"
"testing"

"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/jhttp"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/require"
)

func TestInstallContractWithCLI(t *testing.T) {
NewCLITest(t)
output, err := runCLICommand(t, "contract install --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_hello_world.wasm")
require.NoError(t, err)
wasm := getHelloWorldContract(t)
contractHash := xdr.Hash(sha256.Sum256(wasm))
require.Contains(t, string(output), contractHash.HexString())
}

func runCLICommand(t *testing.T, cmd string) ([]byte, error) {
baseCmdArgs := []string{"run", "--", "--vv"}
args := strings.Split(cmd, " ")
args = append(baseCmdArgs, args...)
c := exec.Command("cargo", args...)
c.Env = append(os.Environ(),
fmt.Sprintf("RPC_URL=http://localhost:%d/", sorobanRPCPort),
fmt.Sprintf("NETWORK_PASPRHASE=%s", StandaloneNetworkPassphrase),
)
return c.Output()
}

func NewCLITest(t *testing.T) *Test {
test := NewTest(t)
ch := jhttp.NewChannel(test.sorobanRPCURL(), nil)
client := jrpc2.NewClient(ch, nil)

sourceAccount := keypair.Root(StandaloneNetworkPassphrase)

// Create default account used byt the CLI
tx, err := txnbuild.NewTransaction(txnbuild.TransactionParams{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: keypair.Root(StandaloneNetworkPassphrase).Address(),
Sequence: 1,
},
IncrementSequenceNum: false,
Operations: []txnbuild.Operation{&txnbuild.CreateAccount{
Destination: "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4",
Amount: "100000",
}},
BaseFee: txnbuild.MinBaseFee,
Memo: nil,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})
require.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)
return test
}
35 changes: 0 additions & 35 deletions cmd/soroban-rpc/internal/test/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"fmt"
"os"
"os/exec"
"path"
"runtime"
"testing"
Expand Down Expand Up @@ -837,37 +836,3 @@ func TestSimulateTransactionBumpAndRestoreFootprint(t *testing.T) {
assert.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)
}

func TestInstallContractWithCLI(t *testing.T) {
test := NewTest(t)
ch := jhttp.NewChannel(test.sorobanRPCURL(), nil)
client := jrpc2.NewClient(ch, nil)

sourceAccount := keypair.Root(StandaloneNetworkPassphrase)

tx, err := txnbuild.NewTransaction(txnbuild.TransactionParams{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: keypair.Root(StandaloneNetworkPassphrase).Address(),
Sequence: 1,
},
IncrementSequenceNum: false,
Operations: []txnbuild.Operation{&txnbuild.CreateAccount{
Destination: "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4",
Amount: "100000",
}},
BaseFee: txnbuild.MinBaseFee,
Memo: nil,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})
require.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)
cmd := exec.Command("cargo", "run", "--", "--vv", "contract", "install", "--wasm", "../../../../target/wasm32-unknown-unknown/test-wasms/test_hello_world.wasm", "--rpc-url", "http://localhost:8000/", "--network-passphrase", "Standalone Network ; February 2017")
require.NoError(t, err)
res, err := cmd.Output()
require.NoError(t, err)
wasm := getHelloWorldContract(t)
contractHash := xdr.Hash(sha256.Sum256(wasm))
require.Contains(t, string(res), contractHash.HexString())
}
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stellar/go v0.0.0-20230901002747-400590c5cce4 h1:SUkKaeW+G+KQ/LJwkN+li/ws/aSpJVsyZW1uhJHPY4k=
github.com/stellar/go v0.0.0-20230901002747-400590c5cce4/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg=
github.com/stellar/go v0.0.0-20230905091142-93d39b0d0bb6 h1:m9e6QQZFXwQTHPi67CP+MrcCHJNGROhtvGUM1OazNGQ=
github.com/stellar/go v0.0.0-20230905091142-93d39b0d0bb6/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg=
github.com/stellar/go v0.0.0-20230905155702-ebdad11ae10b h1:Xn6A3V/qsY+tujIPivASR5VqsPg/crRTzwgU1oD+UFc=
github.com/stellar/go v0.0.0-20230905155702-ebdad11ae10b/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg=
github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583 h1:oC7naR8IBqtWV/b+G91gTOe+jR52+GpkXhCxEyYawYY=
github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg=
github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee h1:fbVs0xmXpBvVS4GBeiRmAE3Le70ofAqFMch1GTiq/e8=
Expand Down

0 comments on commit f8b5d72

Please sign in to comment.