Skip to content

Commit

Permalink
cli: fix TestNEP17Balance test
Browse files Browse the repository at this point in the history
As there was a race in gas balance the `e.Chain.GetTokenLastUpdated`
needed before checking the balance for synchronisation rpc request
result and chain's value.

Close #2960

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Feb 19, 2024
1 parent 71fb759 commit 49a41ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cli/nep_test/nep17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -64,12 +65,17 @@ func TestNEP17Balance(t *testing.T) {
e.CheckNextLine(t, "^\\s*$")
})
t.Run("all accounts", func(t *testing.T) {
getUtilityTokenBalance := func(acc util.Uint160) *big.Int {
_, err := e.Chain.GetTokenLastUpdated(acc)
require.NoError(t, err)
return e.Chain.GetUtilityTokenBalance(acc)
}
e.Run(t, cmdbase...)
addr1, err := address.StringToUint160("Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn")
require.NoError(t, err)
e.CheckNextLine(t, "^Account "+address.Uint160ToString(addr1))
e.CheckNextLine(t, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
balance := e.Chain.GetUtilityTokenBalance(addr1)
balance := getUtilityTokenBalance(addr1)
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
e.CheckNextLine(t, "^\\s*Updated:")
e.CheckNextLine(t, "^\\s*$")
Expand All @@ -87,7 +93,7 @@ func TestNEP17Balance(t *testing.T) {
line := e.GetNextLine(t)
if strings.Contains(line, "GAS") {
e.CheckLine(t, line, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
balance = e.Chain.GetUtilityTokenBalance(addr3)
balance = getUtilityTokenBalance(addr3)
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+fixedn.Fixed8(balance.Int64()).String()+"$")
e.CheckNextLine(t, "^\\s*Updated:")
} else {
Expand Down

0 comments on commit 49a41ff

Please sign in to comment.