Skip to content

Commit

Permalink
Add test and fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Dec 11, 2024
1 parent defe84f commit ff4594c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
10 changes: 5 additions & 5 deletions clients/stellarcore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type GenSorobanConfig struct {
BaseSeqNum uint32
NetworkPassphrase string
// TODO: Should we ask core to sign the tx or should we do it ourselves?
SigningKey keypair.Full
SigningKey *keypair.Full
// looks for `stellar-core` in the system PATH if empty
StellarCorePath string
}
Expand All @@ -113,12 +113,12 @@ func GenSorobanConfigUpgradeTxAndKey(
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
fields := strings.Fields(string(out))
if len(fields) < 4 {
lines := strings.Split(string(out), "\n")
if len(lines) < 9 {
return nil, xdr.ConfigUpgradeSetKey{}, fmt.Errorf("get-settings-upgrade-txs: unexpected output: %q", string(out))
}
txsB64 := fields[0:3]
keyB64 := fields[3]
txsB64 := []string{lines[0], lines[2], lines[4], lines[6]}
keyB64 := lines[8]

txs := make([]xdr.TransactionEnvelope, len(txsB64))
for i, txB64 := range txsB64 {
Expand Down
39 changes: 39 additions & 0 deletions clients/stellarcore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"io"
"net/http"
"net/url"
"os"
"os/exec"
"testing"

"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
proto "github.com/stellar/go/protocols/stellarcore"
"github.com/stellar/go/support/http/httptest"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -135,3 +138,39 @@ func TestGetLedgerEntries(t *testing.T) {
require.Equal(t, "pretend this is XDR lol", resp.Entries[0].Entry)
require.Equal(t, "pretend this is another XDR lol", resp.Entries[1].Entry)
}

func TestGenSorobanConfigUpgradeTxAndKey(t *testing.T) {
coreBinary := os.Getenv("STELLAR_CORE_BINARY_PATH")
if coreBinary == "" {
var err error
coreBinary, err = exec.LookPath("stellar-core")
if err != nil {
t.Skip("couldn't find stellar core binary")
}
}
key, err := keypair.ParseFull("SB6VZS57IY25334Y6F6SPGFUNESWS7D2OSJHKDPIZ354BK3FN5GBTS6V")
require.NoError(t, err)
funcConfig := GenSorobanConfig{
BaseSeqNum: 1,
NetworkPassphrase: network.TestNetworkPassphrase,
SigningKey: key,
StellarCorePath: coreBinary,
}
config := xdr.ConfigUpgradeSet{
UpdatedEntry: []xdr.ConfigSettingEntry{
{
ConfigSettingId: xdr.ConfigSettingIdConfigSettingContractComputeV0,
ContractCompute: &xdr.ConfigSettingContractComputeV0{
LedgerMaxInstructions: 1000,
TxMaxInstructions: 100,
FeeRatePerInstructionsIncrement: 1000,
TxMemoryLimit: 10,
},
},
},
}

txs, _, err := GenSorobanConfigUpgradeTxAndKey(funcConfig, config)
require.NoError(t, err)
require.Len(t, txs, 4)
}

0 comments on commit ff4594c

Please sign in to comment.