|
1 | 1 | package methods |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "encoding/base64" |
5 | 6 | "encoding/json" |
| 7 | + "fmt" |
6 | 8 | "testing" |
7 | 9 |
|
| 10 | + "github.com/creachadair/jrpc2" |
8 | 11 | "github.com/stretchr/testify/require" |
9 | 12 |
|
10 | 13 | protocol "github.com/stellar/go-stellar-sdk/protocols/rpc" |
| 14 | + "github.com/stellar/go-stellar-sdk/support/log" |
11 | 15 | "github.com/stellar/go-stellar-sdk/xdr" |
12 | 16 |
|
13 | 17 | "github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/preflight" |
@@ -142,3 +146,90 @@ func TestLedgerEntryChange(t *testing.T) { |
142 | 146 | require.ErrorIs(t, err, errMissingDiff) |
143 | 147 | require.Equal(t, protocol.LedgerEntryChange{}, change) |
144 | 148 | } |
| 149 | + |
| 150 | +type panicPreflightGetter struct{} |
| 151 | + |
| 152 | +func (panicPreflightGetter) GetPreflight( |
| 153 | + context.Context, |
| 154 | + preflight.GetterParameters, |
| 155 | +) (preflight.Preflight, error) { |
| 156 | + panic("unexpected GetPreflight call") |
| 157 | +} |
| 158 | + |
| 159 | +func TestSimulateTransactionFeeBumpMissingSorobanData(t *testing.T) { |
| 160 | + logger := log.New() |
| 161 | + ledgerReader := &MockLedgerReader{} |
| 162 | + handler := NewSimulateTransactionHandler(logger, ledgerReader, nil, panicPreflightGetter{}) |
| 163 | + |
| 164 | + txEnvelope := feeBumpExtendFootprintMissingSorobanData(t) |
| 165 | + txB64, err := xdr.MarshalBase64(txEnvelope) |
| 166 | + require.NoError(t, err) |
| 167 | + |
| 168 | + requestJSON := fmt.Sprintf(`{ |
| 169 | +"jsonrpc": "2.0", |
| 170 | +"id": 1, |
| 171 | +"method": "simulateTransaction", |
| 172 | +"params": { "transaction": "%s" } |
| 173 | +}`, txB64) |
| 174 | + requests, err := jrpc2.ParseRequests([]byte(requestJSON)) |
| 175 | + require.NoError(t, err) |
| 176 | + require.Len(t, requests, 1) |
| 177 | + |
| 178 | + resp, err := handler(t.Context(), requests[0].ToRequest()) |
| 179 | + require.NoError(t, err) |
| 180 | + |
| 181 | + simResp, ok := resp.(protocol.SimulateTransactionResponse) |
| 182 | + require.True(t, ok) |
| 183 | + require.Equal(t, |
| 184 | + "To perform a SimulateTransaction for ExtendFootprintTtl or RestoreFootprint operations,"+ |
| 185 | + " SorobanTransactionData must be provided", |
| 186 | + simResp.Error, |
| 187 | + ) |
| 188 | +} |
| 189 | + |
| 190 | +func feeBumpExtendFootprintMissingSorobanData(t *testing.T) xdr.TransactionEnvelope { |
| 191 | + t.Helper() |
| 192 | + |
| 193 | + sourceAccountID := xdr.MustAddress("GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON") |
| 194 | + source := (&sourceAccountID).ToMuxedAccount() |
| 195 | + feeSourceAccountID := xdr.MustAddress("GBXGQJWVLWOYHFLVTKWV5FGHA3LNYY2JQKM7OAJAUEQFU6LPCSEFVXON") |
| 196 | + feeSource := (&feeSourceAccountID).ToMuxedAccount() |
| 197 | + |
| 198 | + op := xdr.Operation{ |
| 199 | + Body: xdr.OperationBody{ |
| 200 | + Type: xdr.OperationTypeExtendFootprintTtl, |
| 201 | + ExtendFootprintTtlOp: &xdr.ExtendFootprintTtlOp{ |
| 202 | + Ext: xdr.ExtensionPoint{V: 0}, |
| 203 | + ExtendTo: xdr.Uint32(100), |
| 204 | + }, |
| 205 | + }, |
| 206 | + } |
| 207 | + |
| 208 | + tx := xdr.Transaction{ |
| 209 | + SourceAccount: source, |
| 210 | + Fee: xdr.Uint32(100), |
| 211 | + SeqNum: xdr.SequenceNumber(1), |
| 212 | + Cond: xdr.Preconditions{Type: xdr.PreconditionTypePrecondNone}, |
| 213 | + Memo: xdr.Memo{Type: xdr.MemoTypeMemoNone}, |
| 214 | + Operations: []xdr.Operation{op}, |
| 215 | + Ext: xdr.TransactionExt{V: 0}, |
| 216 | + } |
| 217 | + |
| 218 | + innerV1 := xdr.TransactionV1Envelope{Tx: tx} |
| 219 | + innerTx := xdr.FeeBumpTransactionInnerTx{ |
| 220 | + Type: xdr.EnvelopeTypeEnvelopeTypeTx, |
| 221 | + V1: &innerV1, |
| 222 | + } |
| 223 | + feeBumpTx := xdr.FeeBumpTransaction{ |
| 224 | + FeeSource: feeSource, |
| 225 | + Fee: xdr.Int64(1000), |
| 226 | + InnerTx: innerTx, |
| 227 | + Ext: xdr.FeeBumpTransactionExt{V: 0}, |
| 228 | + } |
| 229 | + feeBumpEnvelope := xdr.FeeBumpTransactionEnvelope{Tx: feeBumpTx} |
| 230 | + |
| 231 | + return xdr.TransactionEnvelope{ |
| 232 | + Type: xdr.EnvelopeTypeEnvelopeTypeTxFeeBump, |
| 233 | + FeeBump: &feeBumpEnvelope, |
| 234 | + } |
| 235 | +} |
0 commit comments