Skip to content

Commit

Permalink
feat: try invoking CLI from go test (#927)
Browse files Browse the repository at this point in the history
* feat: try invoking CLI from go test

* fix: use require and remove sleep

* fix: invoke CLI directly instead of through test; try bumping seq_num

* fix: Prefix test with Test

* fix: generate hash so test passes when file is updated

---------

Co-authored-by: Alfonso Acosta <[email protected]>
  • Loading branch information
willemneal and 2opremio authored Sep 7, 2023
1 parent 89f5a23 commit 16ada04
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ jobs:

- name: Build soroban contract fixtures
run: |
rustup update
rustup target add wasm32-unknown-unknown
make build-test-wasms
rustup update
rustup target add wasm32-unknown-unknown
make build_rust
make build-test-wasms
- name: Install Captive Core
run: |
Expand Down
35 changes: 35 additions & 0 deletions cmd/soroban-rpc/internal/test/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"fmt"
"os"
"os/exec"
"path"
"runtime"
"testing"
Expand Down Expand Up @@ -836,3 +837,37 @@ 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())
}

0 comments on commit 16ada04

Please sign in to comment.