Skip to content

Commit c1bd3e8

Browse files
authored
Merge pull request #19 from kaleido-io/uts
Add policy engine tests for known transaction case
2 parents 871d2ae + ac5692d commit c1bd3e8

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

pkg/policyengines/simple/simple_policy_engine.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func (p *simplePolicyEngine) submitTX(ctx context.Context, cAPI ffcapi.API, mtx
133133
log.L(ctx).Debugf("Transaction %s at nonce %s / %d known with hash: %s (%s)", mtx.ID, mtx.TransactionHeaders.From, mtx.Nonce.Int64(), mtx.TransactionHash, err)
134134
return "", nil
135135
}
136-
// TODO: to cover the edge case where we had a timeout or other failure during the initial TransactionSend, we need to
137-
// be able to re-calculate the hash that we would expect for the transaction.
136+
// Note: to cover the edge case where we had a timeout or other failure during the initial TransactionSend,
137+
// a policy engine implementation would need to be able to re-calculate the hash that we would expect for the transaction.
138138
// This would require a new FFCAPI API to calculate that hash, which requires the connector to perform the signing
139139
// without submission to the node. For example using `eth_signTransaction` for EVM JSON/RPC.
140140
return reason, err

pkg/policyengines/simple/simple_policy_engine_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,34 @@ func TestWarnStaleWarningCannotParse(t *testing.T) {
403403
mockFFCAPI.AssertExpectations(t)
404404
}
405405

406+
func TestKnownTransactionHashKnown(t *testing.T) {
407+
f, conf := newTestPolicyEngineFactory(t)
408+
conf.Set(FixedGasPrice, `12345`)
409+
conf.SubSection(GasOracleConfig).Set(GasOracleMode, GasOracleModeDisabled)
410+
p, err := f.NewPolicyEngine(context.Background(), conf)
411+
assert.NoError(t, err)
412+
413+
mtx := &apitypes.ManagedTX{
414+
TransactionData: "SOME_RAW_TX_BYTES",
415+
PolicyInfo: fftypes.JSONAnyPtr("!not json!"),
416+
TransactionHeaders: ffcapi.TransactionHeaders{
417+
From: "0x6b7cfa4cf9709d3b3f5f7c22de123d2e16aee712",
418+
},
419+
TransactionHash: "0x01020304",
420+
}
421+
422+
mockFFCAPI := &ffcapimocks.API{}
423+
mockFFCAPI.On("TransactionSend", mock.Anything, mock.Anything).
424+
Return(nil, ffcapi.ErrorKnownTransaction, fmt.Errorf("Known transaction"))
425+
426+
ctx := context.Background()
427+
updated, _, err := p.Execute(ctx, mockFFCAPI, mtx)
428+
assert.NoError(t, err)
429+
assert.True(t, updated)
430+
431+
mockFFCAPI.AssertExpectations(t)
432+
}
433+
406434
func TestWarnStaleAdditionalWarningResubmitFail(t *testing.T) {
407435
f, conf := newTestPolicyEngineFactory(t)
408436
conf.Set(FixedGasPrice, `12345`)

0 commit comments

Comments
 (0)