Merge pull request #3396 from nspcc-dev/fix-TestNotary

services: allow some slippage in TestNotary
This commit is contained in:
Roman Khimov 2024-04-03 23:26:00 +03:00 committed by GitHub
commit f6901806a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -492,6 +492,8 @@ func TestNotary(t *testing.T) {
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, r, 1, false)
checkFallbackTxs(t, r, false)
@ -504,10 +506,14 @@ func TestNotary(t *testing.T) {
// check PostPersist with finalisation error
setFinalizeWithError(true)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
// check PostPersist without finalisation error
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), true)
// PostPersist: complete main transaction, multisignature account
@ -517,11 +523,15 @@ func TestNotary(t *testing.T) {
// check PostPersist with finalisation error
setFinalizeWithError(true)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// check PostPersist without finalisation error
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), true)
checkFallbackTxs(t, requests, false)
@ -530,15 +540,19 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteStandardRequest(t, 3, false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
// check PostPersist for valid fallbacks with finalisation error
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// check PostPersist for valid fallbacks without finalisation error
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, true)
@ -549,15 +563,19 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
// check PostPersist for valid fallbacks with finalisation error
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// check PostPersist for valid fallbacks without finalisation error
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests[:nSigs], true)
// the rest of fallbacks should also be applied even if the main tx was already constructed by the moment they were sent
@ -568,7 +586,7 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteStandardRequest(t, 5, false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
// some of fallbacks should fail finalisation
unluckies = []*payload.P2PNotaryRequest{requests[0], requests[4]}
@ -576,6 +594,8 @@ func TestNotary(t *testing.T) {
setChoosy(true)
// check PostPersist for lucky fallbacks
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, lucky, true)
checkFallbackTxs(t, unluckies, false)
@ -584,6 +604,8 @@ func TestNotary(t *testing.T) {
setFinalizeWithError(false)
// check PostPersist for unlucky fallbacks
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, lucky, true)
checkFallbackTxs(t, unluckies, true)
@ -596,12 +618,11 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteStandardRequest(t, 5, false, 1, 7, 11, 15, 19)
checkFallbackTxs(t, requests, false)
// generate blocks to reach the most earlier fallback's NVB
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
// Here and below add +1 slippage to ensure that PostPersist for (nvbDiffFallback+1) height is properly handled, i.e.
// to exclude race condition when main transaction is finalized between `finalizeWithError` disabling and new block addition.
e.GenerateNewBlocks(t, int((nvbDiffFallback+1)+1))
require.NoError(t, err)
// check PostPersist for valid fallbacks without finalisation error
// Add a block before allowing tx to be finalized without error to exclude race condition when
// main transaction is finalized between `finalizeWithError` disabling and new block addition.
e.AddNewBlock(t)
setFinalizeWithError(false)
for i := range requests {
e.AddNewBlock(t)
@ -620,13 +641,15 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteStandardRequest(t, 4, false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid and remove one fallback
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
ntr1.OnRequestRemoval(requests[3])
// non of the fallbacks should be completed
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// set account back for the next tests
@ -638,13 +661,15 @@ func TestNotary(t *testing.T) {
requests, requesters = checkCompleteStandardRequest(t, 4, false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid and remove one fallback
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
unlucky := requests[3]
ntr1.OnRequestRemoval(unlucky)
// rest of the fallbacks should be completed
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests[:3], true)
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
@ -653,7 +678,7 @@ func TestNotary(t *testing.T) {
setFinalizeWithError(true)
requests, requesters = checkCompleteStandardRequest(t, 4, false)
// remove all fallbacks
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
for i := range requests {
ntr1.OnRequestRemoval(requests[i])
@ -661,12 +686,16 @@ func TestNotary(t *testing.T) {
// then the whole request should be removed, i.e. there are no completed transactions
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// OnRequestRemoval: signature request, remove unexisting fallback
ntr1.OnRequestRemoval(requests[0])
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
@ -678,13 +707,15 @@ func TestNotary(t *testing.T) {
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// make fallbacks valid and remove the last fallback
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
unlucky = requests[nSigs-1]
ntr1.OnRequestRemoval(unlucky)
// then (m-1) out of n fallbacks should be completed
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests[:nSigs-1], true)
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
@ -695,7 +726,7 @@ func TestNotary(t *testing.T) {
setFinalizeWithError(true)
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
// make fallbacks valid and then remove all of them
e.GenerateNewBlocks(t, int(nvbDiffFallback))
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
require.NoError(t, err)
for i := range requests {
ntr1.OnRequestRemoval(requests[i])
@ -703,12 +734,16 @@ func TestNotary(t *testing.T) {
// then the whole request should be removed, i.e. there are no completed transactions
setFinalizeWithError(false)
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)
// // OnRequestRemoval: multisignature request, remove unexisting fallbac, i.e. there still shouldn't be any completed transactions after this
ntr1.OnRequestRemoval(requests[0])
e.AddNewBlock(t)
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
e.AddNewBlock(t)
checkMainTx(t, requesters, requests, len(requests), false)
checkFallbackTxs(t, requests, false)