From e0f406fd3a0b19cf785fef3e3a4890e1b4696de2 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 4 Sep 2020 16:03:31 +0300 Subject: [PATCH] rpc/client: add constant to ValidUntilBlock There are 2 problems: 1. `getvalidators` RPC can return empty list. 2. `+1` in single node can be too resrictive. Proper solution for (1) may require requesting standby validators. Here we add constant to fix occasional test failures. --- pkg/rpc/client/rpc.go | 2 +- pkg/rpc/client/rpc_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index d0bca2474..0d8ca01ff 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -489,7 +489,7 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) { expiresAt: blockCount + cacheTimeout, } } - return blockCount + validatorsCount, nil + return blockCount + validatorsCount + 1, nil } // AddNetworkFee adds network fee for each witness script and optional extra diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 5845b3065..8fea9d613 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -1321,14 +1321,14 @@ func TestCalculateValidUntilBlock(t *testing.T) { validUntilBlock, err := c.CalculateValidUntilBlock() assert.NoError(t, err) - assert.Equal(t, uint32(54), validUntilBlock) + assert.Equal(t, uint32(55), validUntilBlock) assert.Equal(t, 1, getBlockCountCalled) assert.Equal(t, 1, getValidatorsCalled) // check, whether caching is working validUntilBlock, err = c.CalculateValidUntilBlock() assert.NoError(t, err) - assert.Equal(t, uint32(54), validUntilBlock) + assert.Equal(t, uint32(55), validUntilBlock) assert.Equal(t, 2, getBlockCountCalled) assert.Equal(t, 1, getValidatorsCalled) }