diff --git a/cmd/soroban-rpc/internal/methods/get_events_test.go b/cmd/soroban-rpc/internal/methods/get_events_test.go index cfbc5b7d8..17289ff0b 100644 --- a/cmd/soroban-rpc/internal/methods/get_events_test.go +++ b/cmd/soroban-rpc/internal/methods/get_events_test.go @@ -1071,9 +1071,14 @@ func ledgerCloseMetaWithEvents(sequence uint32, closeTimestamp int64, txMeta ... Body: xdr.OperationBody{ Type: xdr.OperationTypeInvokeHostFunction, InvokeHostFunctionOp: &xdr.InvokeHostFunctionOp{ - Function: xdr.HostFunction{ - Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract, - InvokeArgs: &xdr.ScVec{}, + Functions: []xdr.HostFunction{ + { + Args: xdr.HostFunctionArgs{ + Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract, + InvokeContract: &xdr.ScVec{}, + }, + Auth: []xdr.ContractAuth{}, + }, }, }, }, diff --git a/cmd/soroban-rpc/internal/test/get_ledger_entries_test.go b/cmd/soroban-rpc/internal/test/get_ledger_entries_test.go index 287ed5763..ca625940f 100644 --- a/cmd/soroban-rpc/internal/test/get_ledger_entries_test.go +++ b/cmd/soroban-rpc/internal/test/get_ledger_entries_test.go @@ -105,9 +105,9 @@ func TestGetLedgerEntriesSucceeds(t *testing.T) { txStatusResponse := getTransaction(t, client, sendTxResponse.Hash) assert.Equal(t, methods.TransactionStatusSuccess, txStatusResponse.Status) - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: testContract}.MarshalBinary() + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: testContract}.MarshalBinary() assert.NoError(t, err) - contractHash := sha256.Sum256(installContractCodeArgs) + contractHash := sha256.Sum256(uploadContractCodeArgs) contractKeyB64, err := xdr.MarshalBase64(xdr.LedgerKey{ Type: xdr.LedgerEntryTypeContractCode, ContractCode: &xdr.LedgerKeyContractCode{ @@ -140,7 +140,7 @@ func TestGetLedgerEntriesSucceeds(t *testing.T) { var result methods.GetLedgerEntriesResponse err = client.CallResult(context.Background(), "getLedgerEntries", request, &result) assert.NoError(t, err) - assert.Equal(t, 1, len(result.Entries)) + require.Equal(t, 1, len(result.Entries)) assert.Greater(t, result.LatestLedger, int64(0)) var firstEntry xdr.LedgerEntryData diff --git a/cmd/soroban-rpc/internal/test/get_ledger_entry_test.go b/cmd/soroban-rpc/internal/test/get_ledger_entry_test.go index f2672027e..9f4e2ef1d 100644 --- a/cmd/soroban-rpc/internal/test/get_ledger_entry_test.go +++ b/cmd/soroban-rpc/internal/test/get_ledger_entry_test.go @@ -98,9 +98,9 @@ func TestGetLedgerEntrySucceeds(t *testing.T) { txStatusResponse := getTransaction(t, client, sendTxResponse.Hash) assert.Equal(t, methods.TransactionStatusSuccess, txStatusResponse.Status) - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: testContract}.MarshalBinary() + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: testContract}.MarshalBinary() assert.NoError(t, err) - contractHash := sha256.Sum256(installContractCodeArgs) + contractHash := sha256.Sum256(uploadContractCodeArgs) keyB64, err := xdr.MarshalBase64(xdr.LedgerKey{ Type: xdr.LedgerEntryTypeContractCode, ContractCode: &xdr.LedgerKeyContractCode{ diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index 42d734b80..f9eabfcc9 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -42,7 +42,7 @@ func getHelloWorldContract(t *testing.T) []byte { return ret } -func createInvokeHostOperation(sourceAccount string, footprint xdr.LedgerFootprint, contractID xdr.Hash, method string, args ...xdr.ScVal) *txnbuild.InvokeHostFunction { +func createInvokeHostOperation(sourceAccount string, ext xdr.TransactionExt, contractID xdr.Hash, method string, args ...xdr.ScVal) *txnbuild.InvokeHostFunctions { var contractIDBytes = xdr.ScBytes(contractID[:]) methodSymbol := xdr.ScSymbol(method) parameters := xdr.ScVec{ @@ -56,23 +56,28 @@ func createInvokeHostOperation(sourceAccount string, footprint xdr.LedgerFootpri }, } parameters = append(parameters, args...) - return &txnbuild.InvokeHostFunction{ - Footprint: footprint, - Function: xdr.HostFunction{ - Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract, - InvokeArgs: ¶meters, + return &txnbuild.InvokeHostFunctions{ + + Functions: []xdr.HostFunction{ + { + Args: xdr.HostFunctionArgs{ + Type: xdr.HostFunctionTypeHostFunctionTypeInvokeContract, + InvokeContract: ¶meters, + }, + }, }, + Ext: ext, SourceAccount: sourceAccount, } } -func createInstallContractCodeOperation(t *testing.T, sourceAccount string, contractCode []byte, includeFootprint bool) *txnbuild.InvokeHostFunction { - var footprint xdr.LedgerFootprint - if includeFootprint { - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: contractCode}.MarshalBinary() +func createInstallContractCodeOperation(t *testing.T, sourceAccount string, contractCode []byte, includeExt bool) *txnbuild.InvokeHostFunctions { + var ext xdr.TransactionExt + if includeExt { + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: contractCode}.MarshalBinary() assert.NoError(t, err) - contractHash := sha256.Sum256(installContractCodeArgs) - footprint = xdr.LedgerFootprint{ + contractHash := sha256.Sum256(uploadContractCodeArgs) + footprint := xdr.LedgerFootprint{ ReadWrite: []xdr.LedgerKey{ { Type: xdr.LedgerEntryTypeContractCode, @@ -82,29 +87,48 @@ func createInstallContractCodeOperation(t *testing.T, sourceAccount string, cont }, }, } + ext = xdr.TransactionExt{ + V: 1, + SorobanData: &xdr.SorobanTransactionData{ + Resources: xdr.SorobanResources{ + Footprint: footprint, + Instructions: 0, + ReadBytes: 0, + WriteBytes: 0, + ExtendedMetaDataSizeBytes: 0, + }, + RefundableFee: 0, + Ext: xdr.ExtensionPoint{}, + }, + } } - return &txnbuild.InvokeHostFunction{ - Footprint: footprint, - Function: xdr.HostFunction{ - Type: xdr.HostFunctionTypeHostFunctionTypeInstallContractCode, - InstallContractCodeArgs: &xdr.InstallContractCodeArgs{ - Code: contractCode, + return &txnbuild.InvokeHostFunctions{ + Ext: ext, + Functions: []xdr.HostFunction{ + { + Args: xdr.HostFunctionArgs{ + Type: xdr.HostFunctionTypeHostFunctionTypeUploadContractWasm, + UploadContractWasm: &xdr.UploadContractWasmArgs{ + Code: contractCode, + }, + }, + Auth: []xdr.ContractAuth{}, }, }, SourceAccount: sourceAccount, } } -func createCreateContractOperation(t *testing.T, sourceAccount string, contractCode []byte, networkPassphrase string, includeFootprint bool) *txnbuild.InvokeHostFunction { +func createCreateContractOperation(t *testing.T, sourceAccount string, contractCode []byte, networkPassphrase string, includeExt bool) *txnbuild.InvokeHostFunctions { saltParam := xdr.Uint256(testSalt) - var footprint xdr.LedgerFootprint - if includeFootprint { - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: contractCode}.MarshalBinary() + var ext xdr.TransactionExt + if includeExt { + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: contractCode}.MarshalBinary() assert.NoError(t, err) - contractHash := xdr.Hash(sha256.Sum256(installContractCodeArgs)) - footprint = xdr.LedgerFootprint{ + contractHash := xdr.Hash(sha256.Sum256(uploadContractCodeArgs)) + footprint := xdr.LedgerFootprint{ ReadWrite: []xdr.LedgerKey{ { Type: xdr.LedgerEntryTypeContractData, @@ -125,25 +149,45 @@ func createCreateContractOperation(t *testing.T, sourceAccount string, contractC }, }, } + ext = xdr.TransactionExt{ + V: 1, + SorobanData: &xdr.SorobanTransactionData{ + Resources: xdr.SorobanResources{ + Footprint: footprint, + Instructions: 0, + ReadBytes: 0, + WriteBytes: 0, + ExtendedMetaDataSizeBytes: 0, + }, + RefundableFee: 0, + Ext: xdr.ExtensionPoint{}, + }, + } } - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: contractCode}.MarshalBinary() + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: contractCode}.MarshalBinary() assert.NoError(t, err) - contractHash := xdr.Hash(sha256.Sum256(installContractCodeArgs)) - - return &txnbuild.InvokeHostFunction{ - Footprint: footprint, - Function: xdr.HostFunction{ - Type: xdr.HostFunctionTypeHostFunctionTypeCreateContract, - CreateContractArgs: &xdr.CreateContractArgs{ - ContractId: xdr.ContractId{ - Type: xdr.ContractIdTypeContractIdFromSourceAccount, - Salt: &saltParam, - }, - Source: xdr.ScContractExecutable{ - Type: xdr.ScContractExecutableTypeSccontractExecutableWasmRef, - WasmId: &contractHash, + contractHash := xdr.Hash(sha256.Sum256(uploadContractCodeArgs)) + + return &txnbuild.InvokeHostFunctions{ + Ext: ext, + + Functions: []xdr.HostFunction{ + { + Args: xdr.HostFunctionArgs{ + Type: xdr.HostFunctionTypeHostFunctionTypeCreateContract, + CreateContract: &xdr.CreateContractArgs{ + ContractId: xdr.ContractId{ + Type: xdr.ContractIdTypeContractIdFromSourceAccount, + Salt: &saltParam, + }, + Executable: xdr.ScContractExecutable{ + Type: xdr.ScContractExecutableTypeSccontractExecutableWasmRef, + WasmId: &contractHash, + }, + }, }, + Auth: []xdr.ContractAuth{}, }, }, SourceAccount: sourceAccount, @@ -349,7 +393,7 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) { Operations: []txnbuild.Operation{ createInvokeHostOperation( address, - xdr.LedgerFootprint{}, + xdr.TransactionExt{}, contractID, "auth", xdr.ScVal{ @@ -404,9 +448,9 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) { assert.Equal(t, xdr.ScValTypeScvLedgerKeyContractExecutable, ro1.ContractData.Key.Type) ro2 := obtainedFootprint.ReadOnly[2] assert.Equal(t, xdr.LedgerEntryTypeContractCode, ro2.Type) - installContractCodeArgs, err := xdr.InstallContractCodeArgs{Code: helloWorldContract}.MarshalBinary() + uploadContractCodeArgs, err := xdr.UploadContractWasmArgs{Code: helloWorldContract}.MarshalBinary() assert.NoError(t, err) - contractHash := sha256.Sum256(installContractCodeArgs) + contractHash := sha256.Sum256(uploadContractCodeArgs) assert.Equal(t, xdr.Hash(contractHash), ro2.ContractCode.Hash) assert.NoError(t, err) @@ -458,8 +502,8 @@ func TestSimulateTransactionError(t *testing.T) { client := jrpc2.NewClient(ch, nil) sourceAccount := keypair.Root(StandaloneNetworkPassphrase).Address() - invokeHostOp := createInvokeHostOperation(sourceAccount, xdr.LedgerFootprint{}, xdr.Hash{}, "noMethod") - invokeHostOp.Function.InvokeArgs = &xdr.ScVec{} + invokeHostOp := createInvokeHostOperation(sourceAccount, xdr.TransactionExt{}, xdr.Hash{}, "noMethod") + invokeHostOp.Functions[0].Args.InvokeContract = &xdr.ScVec{} tx, err := txnbuild.NewTransaction(txnbuild.TransactionParams{ SourceAccount: &txnbuild.SimpleAccount{ AccountID: keypair.Root(StandaloneNetworkPassphrase).Address(), diff --git a/cmd/soroban-rpc/internal/test/transaction_test.go b/cmd/soroban-rpc/internal/test/transaction_test.go index e329954e4..a365629dd 100644 --- a/cmd/soroban-rpc/internal/test/transaction_test.go +++ b/cmd/soroban-rpc/internal/test/transaction_test.go @@ -81,8 +81,10 @@ func TestSendTransactionSucceedsWithResults(t *testing.T) { expectedContractID, err := hex.DecodeString("ea9fcb81ae54a29f6b3bf293847d3fd7e9a369fd1c80acafec6abd571317e0c2") assert.NoError(t, err) contractIDBytes := xdr.ScBytes(expectedContractID) - expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvBytes, Bytes: &contractIDBytes} - assert.True(t, expectedScVal.Equals(resultVal)) + expectedScVal := []xdr.ScVal{{Type: xdr.ScValTypeScvBytes, Bytes: &contractIDBytes}} + assert.Equal(t, len(expectedScVal), len(resultVal)) + assert.Equal(t, len(expectedScVal), int(1)) + assert.True(t, expectedScVal[0].Equals(resultVal[0])) expectedResult := xdr.TransactionResult{ FeeCharged: 100, diff --git a/go.mod b/go.mod index 44964b051..af58eb449 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/sirupsen/logrus v1.4.1 github.com/spf13/cobra v0.0.0-20160830174925-9c28e4bbd74e github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189 - github.com/stellar/go v0.0.0-20230420161348-768b7a1aa986 + github.com/stellar/go v0.0.0-20230504013330-a6e68f56e2c5 github.com/stretchr/testify v1.8.0 golang.org/x/mod v0.6.0 ) diff --git a/go.sum b/go.sum index bcb62a220..039329565 100644 --- a/go.sum +++ b/go.sum @@ -169,8 +169,8 @@ github.com/spf13/pflag v0.0.0-20161005214240-4bd69631f475 h1:RtZIgreTwcayPTOw7G5 github.com/spf13/pflag v0.0.0-20161005214240-4bd69631f475/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189 h1:fvB1AFbBd6SfI9Rd0ooAJp8uLkZDbZaLFHi7ZnNP6uI= github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= -github.com/stellar/go v0.0.0-20230420161348-768b7a1aa986 h1:tE4dGZgNRTY9qWt44rVUOLlw8AbMsI19hukfaHsHSp0= -github.com/stellar/go v0.0.0-20230420161348-768b7a1aa986/go.mod h1:DHmAo7QjGEJa0yef6NXOh+083h/S6OsdRhOwav6Om1A= +github.com/stellar/go v0.0.0-20230504013330-a6e68f56e2c5 h1:Q1EX3wSo1hdWzBjMLguMMJxs5DFvGzxVSD9FwiGWpEk= +github.com/stellar/go v0.0.0-20230504013330-a6e68f56e2c5/go.mod h1:DHmAo7QjGEJa0yef6NXOh+083h/S6OsdRhOwav6Om1A= github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee h1:fbVs0xmXpBvVS4GBeiRmAE3Le70ofAqFMch1GTiq/e8= github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=