diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index de33f0721..1cef8e8e9 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -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) { @@ -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, @@ -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 { diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index f9d4f31b0..ea918d13d 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -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" @@ -47,6 +49,7 @@ type Test struct { coreClient *stellarcore.Client + masterAccount txnbuild.Account shutdownOnce sync.Once shutdownCalls []func() } @@ -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)} @@ -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) }