Skip to content

Commit

Permalink
Merge pull request #19 from kaleido-io/uts
Browse files Browse the repository at this point in the history
Add policy engine tests for known transaction case
  • Loading branch information
nguyer authored Aug 15, 2022
2 parents 871d2ae + ac5692d commit c1bd3e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/policyengines/simple/simple_policy_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (p *simplePolicyEngine) submitTX(ctx context.Context, cAPI ffcapi.API, mtx
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)
return "", nil
}
// TODO: to cover the edge case where we had a timeout or other failure during the initial TransactionSend, we need to
// be able to re-calculate the hash that we would expect for the transaction.
// Note: to cover the edge case where we had a timeout or other failure during the initial TransactionSend,
// a policy engine implementation would need to be able to re-calculate the hash that we would expect for the transaction.
// This would require a new FFCAPI API to calculate that hash, which requires the connector to perform the signing
// without submission to the node. For example using `eth_signTransaction` for EVM JSON/RPC.
return reason, err
Expand Down
28 changes: 28 additions & 0 deletions pkg/policyengines/simple/simple_policy_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,34 @@ func TestWarnStaleWarningCannotParse(t *testing.T) {
mockFFCAPI.AssertExpectations(t)
}

func TestKnownTransactionHashKnown(t *testing.T) {
f, conf := newTestPolicyEngineFactory(t)
conf.Set(FixedGasPrice, `12345`)
conf.SubSection(GasOracleConfig).Set(GasOracleMode, GasOracleModeDisabled)
p, err := f.NewPolicyEngine(context.Background(), conf)
assert.NoError(t, err)

mtx := &apitypes.ManagedTX{
TransactionData: "SOME_RAW_TX_BYTES",
PolicyInfo: fftypes.JSONAnyPtr("!not json!"),
TransactionHeaders: ffcapi.TransactionHeaders{
From: "0x6b7cfa4cf9709d3b3f5f7c22de123d2e16aee712",
},
TransactionHash: "0x01020304",
}

mockFFCAPI := &ffcapimocks.API{}
mockFFCAPI.On("TransactionSend", mock.Anything, mock.Anything).
Return(nil, ffcapi.ErrorKnownTransaction, fmt.Errorf("Known transaction"))

ctx := context.Background()
updated, _, err := p.Execute(ctx, mockFFCAPI, mtx)
assert.NoError(t, err)
assert.True(t, updated)

mockFFCAPI.AssertExpectations(t)
}

func TestWarnStaleAdditionalWarningResubmitFail(t *testing.T) {
f, conf := newTestPolicyEngineFactory(t)
conf.Set(FixedGasPrice, `12345`)
Expand Down

0 comments on commit c1bd3e8

Please sign in to comment.