-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test upgrading Protocol 20 to Protocol 21 (#150)
- Loading branch information
Showing
2 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/creachadair/jrpc2" | ||
"github.com/creachadair/jrpc2/jhttp" | ||
"github.com/stellar/go/keypair" | ||
"github.com/stellar/go/txnbuild" | ||
"github.com/stellar/go/xdr" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/db" | ||
) | ||
|
||
func TestUpgradeFrom20To21(t *testing.T) { | ||
if GetCoreMaxSupportedProtocol() != 21 { | ||
t.Skip("Only test this for protocol 21") | ||
} | ||
test := NewTest(t, &TestConfig{ | ||
ProtocolVersion: 20, | ||
}) | ||
|
||
ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) | ||
client := jrpc2.NewClient(ch, nil) | ||
|
||
sourceAccount := keypair.Root(StandaloneNetworkPassphrase) | ||
address := sourceAccount.Address() | ||
account := txnbuild.NewSimpleAccount(address, 0) | ||
|
||
helloWorldContract := getHelloWorldContract(t) | ||
|
||
params := preflightTransactionParams(t, client, txnbuild.TransactionParams{ | ||
SourceAccount: &account, | ||
IncrementSequenceNum: true, | ||
Operations: []txnbuild.Operation{ | ||
createInstallContractCodeOperation(account.AccountID, helloWorldContract), | ||
}, | ||
BaseFee: txnbuild.MinBaseFee, | ||
Preconditions: txnbuild.Preconditions{ | ||
TimeBounds: txnbuild.NewInfiniteTimeout(), | ||
}, | ||
}) | ||
|
||
tx, err := txnbuild.NewTransaction(params) | ||
assert.NoError(t, err) | ||
sendSuccessfulTransaction(t, client, sourceAccount, tx) | ||
|
||
// Upgrade to protocol 21 and re-upload the contract, which should cause a caching of the contract | ||
// estimations | ||
test.UpgradeProtocol(21) | ||
// Wait for the ledger to advance, so that the simulation library passes the right protocol number | ||
rpcDB := test.daemon.GetDB() | ||
initialLedgerSequence, err := db.NewLedgerEntryReader(rpcDB).GetLatestLedgerSequence(context.Background()) | ||
require.Eventually(t, | ||
func() bool { | ||
newLedgerSequence, err := db.NewLedgerEntryReader(rpcDB).GetLatestLedgerSequence(context.Background()) | ||
require.NoError(t, err) | ||
return newLedgerSequence > initialLedgerSequence | ||
}, | ||
time.Minute, | ||
time.Second, | ||
) | ||
|
||
params = preflightTransactionParams(t, client, txnbuild.TransactionParams{ | ||
SourceAccount: &account, | ||
IncrementSequenceNum: true, | ||
Operations: []txnbuild.Operation{ | ||
createInstallContractCodeOperation(account.AccountID, helloWorldContract), | ||
}, | ||
BaseFee: txnbuild.MinBaseFee, | ||
Preconditions: txnbuild.Preconditions{ | ||
TimeBounds: txnbuild.NewInfiniteTimeout(), | ||
}, | ||
}) | ||
|
||
tx, err = txnbuild.NewTransaction(params) | ||
assert.NoError(t, err) | ||
sendSuccessfulTransaction(t, client, sourceAccount, tx) | ||
|
||
params = preflightTransactionParams(t, client, txnbuild.TransactionParams{ | ||
SourceAccount: &account, | ||
IncrementSequenceNum: true, | ||
Operations: []txnbuild.Operation{ | ||
createCreateContractOperation(address, helloWorldContract), | ||
}, | ||
BaseFee: txnbuild.MinBaseFee, | ||
Preconditions: txnbuild.Preconditions{ | ||
TimeBounds: txnbuild.NewInfiniteTimeout(), | ||
}, | ||
}) | ||
|
||
tx, err = txnbuild.NewTransaction(params) | ||
assert.NoError(t, err) | ||
sendSuccessfulTransaction(t, client, sourceAccount, tx) | ||
|
||
contractID := getContractID(t, address, testSalt, StandaloneNetworkPassphrase) | ||
contractFnParameterSym := xdr.ScSymbol("world") | ||
params = preflightTransactionParams(t, client, txnbuild.TransactionParams{ | ||
SourceAccount: &account, | ||
IncrementSequenceNum: true, | ||
Operations: []txnbuild.Operation{ | ||
createInvokeHostOperation( | ||
address, | ||
contractID, | ||
"hello", | ||
xdr.ScVal{ | ||
Type: xdr.ScValTypeScvSymbol, | ||
Sym: &contractFnParameterSym, | ||
}, | ||
), | ||
}, | ||
BaseFee: txnbuild.MinBaseFee, | ||
Preconditions: txnbuild.Preconditions{ | ||
TimeBounds: txnbuild.NewInfiniteTimeout(), | ||
}, | ||
}) | ||
tx, err = txnbuild.NewTransaction(params) | ||
assert.NoError(t, err) | ||
|
||
sendSuccessfulTransaction(t, client, sourceAccount, tx) | ||
} |