Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions internal/tezos/prepare_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (c *tezosConnector) estimateAndAssignTxCost(ctx context.Context, op *codec.
verb = "forced"
}
limits := v.Limits()
if i >= len(costs) {
log.L(ctx).Debugf("OP#%03d: %s fee(%s)=%d gas_limit(%s)=%d storage_limit(%s)=%d (no simulation cost data)",
i, v.Kind(), verb, limits.Fee, verb, limits.GasLimit, verb, limits.StorageLimit,
)
continue
}
log.L(ctx).Debugf("OP#%03d: %s gas_used(sim)=%d storage_used(sim)=%d storage_burn(sim)=%d alloc_burn(sim)=%d fee(%s)=%d gas_limit(%s)=%d storage_limit(%s)=%d ",
i, v.Kind(), costs[i].GasUsed, costs[i].StorageUsed, costs[i].StorageBurn, costs[i].AllocationBurn,
verb, limits.Fee, verb, limits.GasLimit, verb, limits.StorageLimit,
Expand Down
37 changes: 37 additions & 0 deletions internal/tezos/prepare_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,43 @@ func TestTransactionPrepareWithRevealEmptyServerError(t *testing.T) {
assert.Nil(t, resp)
}

func Test_estimateAndAssignTxCostFewerSimResultsThanOpContents(t *testing.T) {
ctx, c, mRPC, done := newTestConnector(t)
defer done()

// Simulate returns only one result, but the op has two contents entries.
// The bounds check should prevent an index-out-of-bounds panic for the second entry.
mRPC.On("Simulate", ctx, mock.Anything, mock.Anything).
Return(&rpc.Receipt{
Op: &rpc.Operation{
Contents: []rpc.TypedOperation{
rpc.Transaction{
Manager: rpc.Manager{
Generic: rpc.Generic{
Metadata: rpc.OperationMetadata{
Result: rpc.OperationResult{
Status: tezos.OpStatusApplied,
},
},
},
},
},
},
},
}, nil)

op := codec.NewOp()
txArgs := contract.TxArgs{}
op.WithContents(txArgs.Encode())
op.WithContents(txArgs.Encode()) // second entry has no corresponding simulation cost

opts := &rpc.DefaultOptions
opts.IgnoreLimits = true

_, err := c.estimateAndAssignTxCost(ctx, op, opts)
assert.NoError(t, err)
}

func Test_getNetworkParamsByName(t *testing.T) {
params := getNetworkParamsByName("ghostnet")
assert.Equal(t, params, tezos.GhostnetParams)
Expand Down
Loading