forked from TrueCloudLab/neoneo-go
Merge pull request #3396 from nspcc-dev/fix-TestNotary
services: allow some slippage in TestNotary
This commit is contained in:
commit
f6901806a8
1 changed files with 47 additions and 12 deletions
|
@ -492,6 +492,8 @@ func TestNotary(t *testing.T) {
|
||||||
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
|
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
|
|
||||||
|
e.AddNewBlock(t)
|
||||||
|
// Allow a single-block slippage since PostPersist is handled by Notary service via block notification routine.
|
||||||
e.AddNewBlock(t)
|
e.AddNewBlock(t)
|
||||||
checkMainTx(t, requesters, r, 1, false)
|
checkMainTx(t, requesters, r, 1, false)
|
||||||
checkFallbackTxs(t, r, false)
|
checkFallbackTxs(t, r, false)
|
||||||
|
@ -504,10 +506,14 @@ func TestNotary(t *testing.T) {
|
||||||
// check PostPersist with finalisation error
|
// check PostPersist with finalisation error
|
||||||
setFinalizeWithError(true)
|
setFinalizeWithError(true)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
// check PostPersist without finalisation error
|
// check PostPersist without finalisation error
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), true)
|
||||||
|
|
||||||
// PostPersist: complete main transaction, multisignature account
|
// PostPersist: complete main transaction, multisignature account
|
||||||
|
@ -517,11 +523,15 @@ func TestNotary(t *testing.T) {
|
||||||
// check PostPersist with finalisation error
|
// check PostPersist with finalisation error
|
||||||
setFinalizeWithError(true)
|
setFinalizeWithError(true)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// check PostPersist without finalisation error
|
// check PostPersist without finalisation error
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), true)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
|
|
||||||
|
@ -530,15 +540,19 @@ func TestNotary(t *testing.T) {
|
||||||
requests, requesters = checkCompleteStandardRequest(t, 3, false)
|
requests, requesters = checkCompleteStandardRequest(t, 3, false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid
|
// make fallbacks valid
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// check PostPersist for valid fallbacks with finalisation error
|
// check PostPersist for valid fallbacks with finalisation error
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// check PostPersist for valid fallbacks without finalisation error
|
// check PostPersist for valid fallbacks without finalisation error
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, true)
|
checkFallbackTxs(t, requests, true)
|
||||||
|
|
||||||
|
@ -549,15 +563,19 @@ func TestNotary(t *testing.T) {
|
||||||
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
|
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid
|
// make fallbacks valid
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// check PostPersist for valid fallbacks with finalisation error
|
// check PostPersist for valid fallbacks with finalisation error
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// check PostPersist for valid fallbacks without finalisation error
|
// check PostPersist for valid fallbacks without finalisation error
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests[:nSigs], true)
|
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
|
// 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)
|
requests, requesters = checkCompleteStandardRequest(t, 5, false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid
|
// make fallbacks valid
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// some of fallbacks should fail finalisation
|
// some of fallbacks should fail finalisation
|
||||||
unluckies = []*payload.P2PNotaryRequest{requests[0], requests[4]}
|
unluckies = []*payload.P2PNotaryRequest{requests[0], requests[4]}
|
||||||
|
@ -576,6 +594,8 @@ func TestNotary(t *testing.T) {
|
||||||
setChoosy(true)
|
setChoosy(true)
|
||||||
// check PostPersist for lucky fallbacks
|
// check PostPersist for lucky fallbacks
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, lucky, true)
|
checkFallbackTxs(t, lucky, true)
|
||||||
checkFallbackTxs(t, unluckies, false)
|
checkFallbackTxs(t, unluckies, false)
|
||||||
|
@ -584,6 +604,8 @@ func TestNotary(t *testing.T) {
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
// check PostPersist for unlucky fallbacks
|
// check PostPersist for unlucky fallbacks
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, lucky, true)
|
checkFallbackTxs(t, lucky, true)
|
||||||
checkFallbackTxs(t, unluckies, 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)
|
requests, requesters = checkCompleteStandardRequest(t, 5, false, 1, 7, 11, 15, 19)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// generate blocks to reach the most earlier fallback's NVB
|
// 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)
|
require.NoError(t, err)
|
||||||
// check PostPersist for valid fallbacks without finalisation error
|
// 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)
|
setFinalizeWithError(false)
|
||||||
for i := range requests {
|
for i := range requests {
|
||||||
e.AddNewBlock(t)
|
e.AddNewBlock(t)
|
||||||
|
@ -620,13 +641,15 @@ func TestNotary(t *testing.T) {
|
||||||
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid and remove one fallback
|
// make fallbacks valid and remove one fallback
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
|
ntr1.UpdateNotaryNodes(keys.PublicKeys{randomAcc.PublicKey()})
|
||||||
ntr1.OnRequestRemoval(requests[3])
|
ntr1.OnRequestRemoval(requests[3])
|
||||||
// non of the fallbacks should be completed
|
// non of the fallbacks should be completed
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// set account back for the next tests
|
// set account back for the next tests
|
||||||
|
@ -638,13 +661,15 @@ func TestNotary(t *testing.T) {
|
||||||
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid and remove one fallback
|
// make fallbacks valid and remove one fallback
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unlucky := requests[3]
|
unlucky := requests[3]
|
||||||
ntr1.OnRequestRemoval(unlucky)
|
ntr1.OnRequestRemoval(unlucky)
|
||||||
// rest of the fallbacks should be completed
|
// rest of the fallbacks should be completed
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests[:3], true)
|
checkFallbackTxs(t, requests[:3], true)
|
||||||
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
|
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
|
||||||
|
@ -653,7 +678,7 @@ func TestNotary(t *testing.T) {
|
||||||
setFinalizeWithError(true)
|
setFinalizeWithError(true)
|
||||||
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
requests, requesters = checkCompleteStandardRequest(t, 4, false)
|
||||||
// remove all fallbacks
|
// remove all fallbacks
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for i := range requests {
|
for i := range requests {
|
||||||
ntr1.OnRequestRemoval(requests[i])
|
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
|
// then the whole request should be removed, i.e. there are no completed transactions
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
|
|
||||||
// OnRequestRemoval: signature request, remove unexisting fallback
|
// OnRequestRemoval: signature request, remove unexisting fallback
|
||||||
ntr1.OnRequestRemoval(requests[0])
|
ntr1.OnRequestRemoval(requests[0])
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
|
|
||||||
|
@ -678,13 +707,15 @@ func TestNotary(t *testing.T) {
|
||||||
checkMainTx(t, requesters, requests, len(requests), false)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
// make fallbacks valid and remove the last fallback
|
// make fallbacks valid and remove the last fallback
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
unlucky = requests[nSigs-1]
|
unlucky = requests[nSigs-1]
|
||||||
ntr1.OnRequestRemoval(unlucky)
|
ntr1.OnRequestRemoval(unlucky)
|
||||||
// then (m-1) out of n fallbacks should be completed
|
// then (m-1) out of n fallbacks should be completed
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests[:nSigs-1], true)
|
checkFallbackTxs(t, requests[:nSigs-1], true)
|
||||||
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
|
require.Nil(t, completedTxes[unlucky.FallbackTransaction.Hash()])
|
||||||
|
@ -695,7 +726,7 @@ func TestNotary(t *testing.T) {
|
||||||
setFinalizeWithError(true)
|
setFinalizeWithError(true)
|
||||||
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
|
requests, requesters = checkCompleteMultisigRequest(t, nSigs, nKeys, false)
|
||||||
// make fallbacks valid and then remove all of them
|
// make fallbacks valid and then remove all of them
|
||||||
e.GenerateNewBlocks(t, int(nvbDiffFallback))
|
e.GenerateNewBlocks(t, int(nvbDiffFallback+1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for i := range requests {
|
for i := range requests {
|
||||||
ntr1.OnRequestRemoval(requests[i])
|
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
|
// then the whole request should be removed, i.e. there are no completed transactions
|
||||||
setFinalizeWithError(false)
|
setFinalizeWithError(false)
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
|
|
||||||
// // OnRequestRemoval: multisignature request, remove unexisting fallbac, i.e. there still shouldn't be any completed transactions after this
|
// // OnRequestRemoval: multisignature request, remove unexisting fallbac, i.e. there still shouldn't be any completed transactions after this
|
||||||
ntr1.OnRequestRemoval(requests[0])
|
ntr1.OnRequestRemoval(requests[0])
|
||||||
e.AddNewBlock(t)
|
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)
|
checkMainTx(t, requesters, requests, len(requests), false)
|
||||||
checkFallbackTxs(t, requests, false)
|
checkFallbackTxs(t, requests, false)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue