Skip to content

Commit

Permalink
Fix CLI wrap test
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Nov 28, 2023
1 parent 8ef8e30 commit 0b9e448
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
50 changes: 37 additions & 13 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ func TestCLICargoTest(t *testing.T) {
}

func TestCLIWrapCustom(t *testing.T) {
NewCLITest(t)
testAccount := getCLIDefaultAccount(t)
strkeyContractID := runSuccessfulCLICmd(t, fmt.Sprintf("lab token wrap --asset=deadbeef:%s", testAccount))
require.Equal(t, "true", runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id=%s -- authorized --id=%s", strkeyContractID, testAccount)))
runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id=%s -- mint --to=%s --amount 1", strkeyContractID, testAccount))
it := NewCLITest(t)
assetCode := "deadbeef"
issuerAccount := getCLIDefaultAccount(t)
strkeyContractID := runSuccessfulCLICmd(t, fmt.Sprintf("lab token wrap --asset=%s:%s", assetCode, issuerAccount))
require.Equal(t, "true", runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id=%s -- authorized --id=%s", strkeyContractID, issuerAccount)))
asset := txnbuild.CreditAsset{
Code: assetCode,
Issuer: issuerAccount,
}
establishAccountTrustline(t, it, it.MasterKey(), it.MasterAccount(), asset)
masterAccount := keypair.Root(StandaloneNetworkPassphrase).Address()
runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id=%s -- mint --to=%s --amount 1", strkeyContractID, masterAccount))
}

func TestCLIWrapNative(t *testing.T) {
Expand Down Expand Up @@ -296,14 +303,9 @@ func fundAccount(t *testing.T, test *Test, account string, amount string) {
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,
SourceAccount: test.MasterAccount(),
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{&txnbuild.CreateAccount{
Destination: account,
Amount: amount,
Expand All @@ -315,7 +317,29 @@ func fundAccount(t *testing.T, test *Test, account string, amount string) {
},
})
require.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)
sendSuccessfulTransaction(t, client, test.MasterKey(), tx)
}

func establishAccountTrustline(t *testing.T, test *Test, kp *keypair.Full, account txnbuild.Account, asset txnbuild.Asset) {
ch := jhttp.NewChannel(test.sorobanRPCURL(), nil)
client := jrpc2.NewClient(ch, nil)

line := asset.MustToChangeTrustAsset()
tx, err := txnbuild.NewTransaction(txnbuild.TransactionParams{
SourceAccount: account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{&txnbuild.ChangeTrust{
Line: line,
Limit: "2000",
}},
BaseFee: txnbuild.MinBaseFee,
Memo: nil,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})
require.NoError(t, err)
sendSuccessfulTransaction(t, client, kp, tx)
}

func parseInt(t *testing.T, s string) uint64 {
Expand Down
15 changes: 15 additions & 0 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/stellar/go/clients/stellarcore"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"

"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/config"
"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/daemon"
Expand Down Expand Up @@ -47,6 +49,7 @@ type Test struct {

coreClient *stellarcore.Client

masterAccount txnbuild.Account
shutdownOnce sync.Once
shutdownCalls []func()
}
Expand All @@ -64,6 +67,10 @@ func NewTest(t *testing.T) *Test {
t: t,
composePath: findDockerComposePath(),
}
i.masterAccount = &txnbuild.SimpleAccount{
AccountID: i.MasterKey().Address(),
Sequence: 0,
}
i.runComposeCommand("up", "--detach", "--quiet-pull", "--no-color")
i.prepareShutdownHandlers()
i.coreClient = &stellarcore.Client{URL: "http://localhost:" + strconv.Itoa(stellarCorePort)}
Expand All @@ -74,6 +81,14 @@ func NewTest(t *testing.T) *Test {
return i
}

func (i *Test) MasterKey() *keypair.Full {
return keypair.Root(StandaloneNetworkPassphrase)
}

func (i *Test) MasterAccount() txnbuild.Account {
return i.masterAccount
}

func (i *Test) sorobanRPCURL() string {
return fmt.Sprintf("http://localhost:%d", sorobanRPCPort)
}
Expand Down

0 comments on commit 0b9e448

Please sign in to comment.