rpc: carefully review places where Client.cache.initDone is used

1. Keep initDone check only for the places where cache is directly accessed.
   We don't need to check it in other places, otherwise we have a mess of
   duplicating checks.
2. Fix bug in code related to block deserialisation. There's no magic, so
   checking that initialisation is done is not enough for proper block
   deserialisation. We need to manually fill StateRootEnabled field.
3. Since transaction doesn't need network magic to compute its hash, we don't
   need to perform Client initialisation before transaction-related requests.
4. Check that cache is initialised before accessing network magic.
5. Refactor the way Policy contract hash is fetched for Client requests.
   We don't really need Client initialisation for that, it's OK to fetch Policy
   hash on-the-fly.
This commit is contained in:
AnnaShaleva 2022-02-21 13:41:14 +03:00 committed by Anna Shaleva
parent 7c1862a9ac
commit 0092330fe1
12 changed files with 81 additions and 71 deletions

View file

@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"net/http"
@ -1913,7 +1914,8 @@ func TestGetNetwork(t *testing.T) {
t.Fatal(err)
}
// network was not initialised
require.Equal(t, netmode.Magic(0), c.GetNetwork())
_, err = c.GetNetwork()
require.True(t, errors.Is(err, errNetworkNotInitialized))
require.Equal(t, false, c.cache.initDone)
})
@ -1923,7 +1925,9 @@ func TestGetNetwork(t *testing.T) {
t.Fatal(err)
}
require.NoError(t, c.Init())
require.Equal(t, netmode.UnitTestNet, c.GetNetwork())
m, err := c.GetNetwork()
require.NoError(t, err)
require.Equal(t, netmode.UnitTestNet, m)
})
}