Skip to content

Commit 445ab97

Browse files
authored
Merge pull request #3360 from nspcc-dev/adj-mempool-err-codes
rpcsrv: fix RPC error codes proposal compatibility
2 parents bfc3aa6 + 82e52c4 commit 445ab97

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pkg/services/rpcsrv/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,7 @@ func getRelayResult(err error, hash util.Uint256) (any, *neorpc.Error) {
26572657
return nil, neorpc.WrapErrorWithData(neorpc.ErrInsufficientNetworkFee, err.Error())
26582658
case errors.Is(err, core.ErrInvalidAttribute):
26592659
return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidAttribute, err.Error())
2660-
case errors.Is(err, core.ErrInsufficientFunds):
2660+
case errors.Is(err, core.ErrMemPoolConflict):
26612661
return nil, neorpc.WrapErrorWithData(neorpc.ErrInsufficientFunds, err.Error())
26622662
case errors.Is(err, core.ErrInvalidSignature):
26632663
return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidSignature, err.Error())

pkg/services/rpcsrv/server_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
26592659
t.Run("insufficient funds", func(t *testing.T) {
26602660
b := testchain.NewBlock(t, chain, 1, 0, newTxWithParams(t, chain, opcode.PUSH1, 10, 899999999999, 1, false))
26612661
body := doRPCCall(fmt.Sprintf(rpc, encodeBinaryToString(t, b)), httpSrv.URL, t)
2662-
checkErrGetResult(t, body, true, neorpc.ErrInsufficientFundsCode)
2662+
checkErrGetResult(t, body, true, neorpc.ErrVerificationFailedCode)
26632663
})
26642664
t.Run("positive", func(t *testing.T) {
26652665
b := testchain.NewBlock(t, chain, 1, 0, newTxWithParams(t, chain, opcode.PUSH1, 10, 0, 1, false))
@@ -3341,6 +3341,23 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
33413341
body2 := doRPCCall(fmt.Sprintf(rpc, rawTx2), httpSrv.URL, t)
33423342
checkErrGetResult(t, body2, true, neorpc.ErrMempoolCapReachedCode)
33433343
})
3344+
t.Run("mempool conflict", func(t *testing.T) {
3345+
chain, _, httpSrv := initClearServerWithCustomConfig(t, func(c *config.Config) {
3346+
c.ProtocolConfiguration.MemPoolSize = 2
3347+
})
3348+
3349+
// Create and push the first transaction with large network fee.
3350+
tx := newTxWithParams(t, chain, opcode.PUSH1, 10, 1, 25, false)
3351+
rawTx := encodeBinaryToString(t, tx)
3352+
body := doRPCCall(fmt.Sprintf(rpc, rawTx), httpSrv.URL, t)
3353+
checkErrGetResult(t, body, false, 0)
3354+
3355+
// Create and push the second transaction, sender doesn't have enough balance to pay for two transactions.
3356+
tx2 := newTxWithParams(t, chain, opcode.PUSH1, 10, 1, 25, false)
3357+
rawTx2 := encodeBinaryToString(t, tx2)
3358+
body2 := doRPCCall(fmt.Sprintf(rpc, rawTx2), httpSrv.URL, t)
3359+
checkErrGetResult(t, body2, true, neorpc.ErrInsufficientFundsCode)
3360+
})
33443361
})
33453362
t.Run("test functions with unsupported states", func(t *testing.T) {
33463363
chain, _, httpSrv := initClearServerWithCustomConfig(t, func(c *config.Config) {
@@ -3380,7 +3397,7 @@ func newTxWithParams(t *testing.T, chain *core.Blockchain, code opcode.Opcode, v
33803397

33813398
height := chain.BlockHeight()
33823399
tx := transaction.New([]byte{byte(code)}, 0)
3383-
tx.Nonce = height + 1
3400+
tx.Nonce = uint32(random.Int(0, math.MaxUint32))
33843401
tx.ValidUntilBlock = height + validUntilIncr
33853402
tx.Signers = []transaction.Signer{{Account: acc0.PrivateKey().GetScriptHash()}}
33863403
tx.SystemFee = systemFee

0 commit comments

Comments
 (0)