Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soroban-rpc: adapt to value overhaul changes #523

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
env:
SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true
SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.7.1-1204.871accefc.focal~soroban
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.8.1-1238.903afe5e1.focal~soroban
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
50 changes: 25 additions & 25 deletions cmd/soroban-rpc/internal/methods/get_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestTopicFilterMatches(t *testing.T) {
Type: xdr.ScValTypeScvSymbol,
Sym: &transferSym,
}
sixtyfour := xdr.Int64(64)
sixtyfour := xdr.Uint64(64)
number := xdr.ScVal{
Type: xdr.ScValTypeScvU63,
U63: &sixtyfour,
Type: xdr.ScValTypeScvU64,
U64: &sixtyfour,
}
star := "*"
for _, tc := range []struct {
Expand Down Expand Up @@ -191,8 +191,8 @@ func TestTopicFilterJSON(t *testing.T) {
assert.NoError(t, json.Unmarshal([]byte("[\"*\"]"), &got))
assert.Equal(t, TopicFilter{{wildcard: &star}}, got)

sixtyfour := xdr.Int64(64)
scval := xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &sixtyfour}
sixtyfour := xdr.Uint64(64)
scval := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &sixtyfour}
scvalstr, err := xdr.MarshalBase64(scval)
assert.NoError(t, err)
assert.NoError(t, json.Unmarshal([]byte(fmt.Sprintf("[%q]", scvalstr)), &got))
Expand Down Expand Up @@ -514,24 +514,24 @@ func TestGetEvents(t *testing.T) {
var txMeta []xdr.TransactionMeta
contractID := xdr.Hash([32]byte{})
for i := 0; i < 10; i++ {
number := xdr.Int64(i)
number := xdr.Uint64(i)
txMeta = append(txMeta, transactionMetaWithEvents(
[]xdr.ContractEvent{
// Generate a unique topic like /counter/4 for each event so we can check
contractEvent(
contractID,
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
},
))
}
assert.NoError(t, store.IngestEvents(ledgerCloseMetaWithEvents(1, now.Unix(), txMeta...)))

number := xdr.Int64(4)
number := xdr.Uint64(4)
handler := eventsRPCHandler{
scanner: store,
maxLimit: 10000,
Expand All @@ -543,7 +543,7 @@ func TestGetEvents(t *testing.T) {
{Topics: []TopicFilter{
[]SegmentFilter{
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter}},
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number}},
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number}},
},
}},
},
Expand All @@ -553,8 +553,8 @@ func TestGetEvents(t *testing.T) {
id := events.Cursor{Ledger: 1, Tx: 5, Op: 0, Event: 0}.String()
assert.NoError(t, err)
value, err := xdr.MarshalBase64(xdr.ScVal{
Type: xdr.ScValTypeScvU63,
U63: &number,
Type: xdr.ScValTypeScvU64,
U64: &number,
})
assert.NoError(t, err)
expected := []EventInfo{
Expand All @@ -576,7 +576,7 @@ func TestGetEvents(t *testing.T) {
store := events.NewMemoryStore("unit-tests", 100)
contractID := xdr.Hash([32]byte{})
otherContractID := xdr.Hash([32]byte{1})
number := xdr.Int64(1)
number := xdr.Uint64(1)
txMeta := []xdr.TransactionMeta{
// This matches neither the contract id nor the topic
transactionMetaWithEvents([]xdr.ContractEvent{
Expand All @@ -585,7 +585,7 @@ func TestGetEvents(t *testing.T) {
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
}),
// This matches the contract id but not the topic
Expand All @@ -595,7 +595,7 @@ func TestGetEvents(t *testing.T) {
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
}),
// This matches the topic but not the contract id
Expand All @@ -604,9 +604,9 @@ func TestGetEvents(t *testing.T) {
otherContractID,
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
}),
// This matches both the contract id and the topic
Expand All @@ -615,9 +615,9 @@ func TestGetEvents(t *testing.T) {
contractID,
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
}),
}
Expand All @@ -636,7 +636,7 @@ func TestGetEvents(t *testing.T) {
Topics: []TopicFilter{
[]SegmentFilter{
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter}},
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number}},
{scval: &xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number}},
},
},
},
Expand All @@ -646,8 +646,8 @@ func TestGetEvents(t *testing.T) {

id := events.Cursor{Ledger: 1, Tx: 4, Op: 0, Event: 0}.String()
value, err := xdr.MarshalBase64(xdr.ScVal{
Type: xdr.ScValTypeScvU63,
U63: &number,
Type: xdr.ScValTypeScvU64,
U64: &number,
})
assert.NoError(t, err)
expected := []EventInfo{
Expand Down Expand Up @@ -722,15 +722,15 @@ func TestGetEvents(t *testing.T) {
contractID := xdr.Hash([32]byte{})
var txMeta []xdr.TransactionMeta
for i := 0; i < 180; i++ {
number := xdr.Int64(i)
number := xdr.Uint64(i)
txMeta = append(txMeta, transactionMetaWithEvents(
[]xdr.ContractEvent{
contractEvent(
contractID,
xdr.ScVec{
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
},
xdr.ScVal{Type: xdr.ScValTypeScvU63, U63: &number},
xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &number},
),
},
))
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
# Note: Please keep the image pinned to an immutable tag matching the Captive Core version.
# This avoid implicit updates which break compatibility between
# the Core container and captive core.
image: ${CORE_IMAGE:-2opremio/stellar-core:19.7.1-1178.e352f0012.focal-soroban}
image: ${CORE_IMAGE:-2opremio/stellar-core:19.8.1-1238.903afe5e1.focal-soroban}
depends_on:
- core-postgres
restart: on-failure
Expand Down
4 changes: 3 additions & 1 deletion cmd/soroban-rpc/internal/test/get_ledger_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func TestGetLedgerEntryNotFound(t *testing.T) {
Type: xdr.LedgerEntryTypeContractData,
ContractData: &xdr.LedgerKeyContractData{
ContractId: contractID,
Key: getContractCodeLedgerKey(),
Key: xdr.ScVal{
Type: xdr.ScValTypeScvLedgerKeyContractExecutable,
},
},
})
require.NoError(t, err)
Expand Down
53 changes: 18 additions & 35 deletions cmd/soroban-rpc/internal/test/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ func getHelloWorldContract(t *testing.T) []byte {
}

func createInvokeHostOperation(sourceAccount string, footprint xdr.LedgerFootprint, contractID xdr.Hash, method string, args ...xdr.ScVal) *txnbuild.InvokeHostFunction {
var contractIDBytes []byte = contractID[:]
contractIDObj := &xdr.ScObject{
Type: xdr.ScObjectTypeScoBytes,
Bin: &contractIDBytes,
}
var contractIDBytes = xdr.ScBytes(contractID[:])
methodSymbol := xdr.ScSymbol(method)
parameters := xdr.ScVec{
xdr.ScVal{
Type: xdr.ScValTypeScvObject,
Obj: &contractIDObj,
Type: xdr.ScValTypeScvBytes,
Bytes: &contractIDBytes,
},
xdr.ScVal{
Type: xdr.ScValTypeScvSymbol,
Expand Down Expand Up @@ -108,7 +104,9 @@ func createCreateContractOperation(t *testing.T, sourceAccount string, contractC
Type: xdr.LedgerEntryTypeContractData,
ContractData: &xdr.LedgerKeyContractData{
ContractId: xdr.Hash(getContractID(t, sourceAccount, testSalt, networkPassphrase)),
Key: getContractCodeLedgerKey(),
Key: xdr.ScVal{
Type: xdr.ScValTypeScvLedgerKeyContractExecutable,
},
},
},
},
Expand Down Expand Up @@ -136,8 +134,8 @@ func createCreateContractOperation(t *testing.T, sourceAccount string, contractC
Type: xdr.ContractIdTypeContractIdFromSourceAccount,
Salt: &saltParam,
},
Source: xdr.ScContractCode{
Type: xdr.ScContractCodeTypeSccontractCodeWasmRef,
Source: xdr.ScContractExecutable{
Type: xdr.ScContractExecutableTypeSccontractExecutableWasmRef,
WasmId: &contractHash,
},
},
Expand All @@ -146,15 +144,6 @@ func createCreateContractOperation(t *testing.T, sourceAccount string, contractC
}
}

func getContractCodeLedgerKey() xdr.ScVal {
ledgerKeyContractCodeAddr := xdr.ScStaticScsLedgerKeyContractCode
contractCodeLedgerKey := xdr.ScVal{
Type: xdr.ScValTypeScvStatic,
Ic: &ledgerKeyContractCodeAddr,
}
return contractCodeLedgerKey
}

func getContractID(t *testing.T, sourceAccount string, salt [32]byte, networkPassphrase string) [32]byte {
networkID := xdr.Hash(sha256.Sum256([]byte(networkPassphrase)))
preImage := xdr.HashIdPreimage{
Expand Down Expand Up @@ -341,13 +330,6 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
})
assert.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)
addressObject := &xdr.ScObject{
Type: xdr.ScObjectTypeScoAddress,
Address: &xdr.ScAddress{
Type: xdr.ScAddressTypeScAddressTypeAccount,
AccountId: &authAccountIDArg,
},
}
tx, err = txnbuild.NewTransaction(txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Expand All @@ -358,8 +340,11 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
contractID,
"auth",
xdr.ScVal{
Type: xdr.ScValTypeScvObject,
Obj: &addressObject,
Type: xdr.ScValTypeScvAddress,
Address: &xdr.ScAddress{
Type: xdr.ScAddressTypeScAddressTypeAccount,
AccountId: &authAccountIDArg,
},
},
xdr.ScVal{
Type: xdr.ScValTypeScvSymbol,
Expand Down Expand Up @@ -387,11 +372,10 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
var obtainedResult xdr.ScVal
err = xdr.SafeUnmarshalBase64(response.Results[0].XDR, &obtainedResult)
assert.NoError(t, err)
assert.Equal(t, xdr.ScValTypeScvObject, obtainedResult.Type)
obj := *obtainedResult.Obj
assert.Equal(t, xdr.ScObjectTypeScoVec, obj.Type)
assert.Len(t, *obj.Vec, 2)
world := (*obj.Vec)[1]
assert.Equal(t, xdr.ScValTypeScvVec, obtainedResult.Type)
assert.NotNil(t, *obtainedResult.Vec)
assert.Len(t, **obtainedResult.Vec, 2)
world := (**obtainedResult.Vec)[1]
assert.Equal(t, xdr.ScValTypeScvSymbol, world.Type)
assert.Equal(t, xdr.ScSymbol("world"), *world.Sym)

Expand All @@ -407,8 +391,7 @@ func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) {
ro1 := obtainedFootprint.ReadOnly[1]
assert.Equal(t, xdr.LedgerEntryTypeContractData, ro1.Type)
assert.Equal(t, xdr.Hash(contractID), ro1.ContractData.ContractId)
assert.Equal(t, xdr.ScValTypeScvStatic, ro1.ContractData.Key.Type)
assert.Equal(t, xdr.ScStaticScsLedgerKeyContractCode, *ro1.ContractData.Key.Ic)
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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/test/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestSendTransactionSucceedsWithResults(t *testing.T) {
resultVal := *invokeHostFunctionResult.Success
expectedContractID, err := hex.DecodeString("ea9fcb81ae54a29f6b3bf293847d3fd7e9a369fd1c80acafec6abd571317e0c2")
assert.NoError(t, err)
expectedObj := &xdr.ScObject{Type: xdr.ScObjectTypeScoBytes, Bin: &expectedContractID}
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvObject, Obj: &expectedObj}
contractIDBytes := xdr.ScBytes(expectedContractID)
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvBytes, Bytes: &contractIDBytes}
assert.True(t, expectedScVal.Equals(resultVal))

expectedResult := xdr.TransactionResult{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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-20230307175517-b2d1e113c534
github.com/stellar/go v0.0.0-20230320165241-a5f3278b8282
github.com/stretchr/testify v1.8.0
golang.org/x/mod v0.6.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,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-20230307175517-b2d1e113c534 h1:ecxXXWGTHRY765WueJi8QCN21Ckxb0XNIRDbNbZ5TG4=
github.com/stellar/go v0.0.0-20230307175517-b2d1e113c534/go.mod h1:QXwuKmYVvqQZlByv0EeNb0Rgog9AP+eMmARcdt3h2rI=
github.com/stellar/go v0.0.0-20230320165241-a5f3278b8282 h1:Lijy4+s8ZwC6omEHHI4zThxxqKkQ0q1JyUn0WLfKFgI=
github.com/stellar/go v0.0.0-20230320165241-a5f3278b8282/go.mod h1:QXwuKmYVvqQZlByv0EeNb0Rgog9AP+eMmARcdt3h2rI=
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=
Expand Down