core: refactor GASRecord handling

We should store each GAS record as
{
    Key: ContractID + RecordsPrefix + RecordID,
    Value: RecordValue,
}
So don't use state.GASRecord for storing anymore. However, it's still
useful to cache GasRecord values by using state.GASRecords, because we
have to keep GASIndexPairs sorted by indexes.
This commit is contained in:
Anna Shaleva 2020-10-21 17:28:45 +03:00
parent 0da01fde7f
commit 0232bbcb0c
4 changed files with 80 additions and 145 deletions

View file

@ -1,40 +0,0 @@
package state
import (
"math/big"
"testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
func TestGASRecord_EncodeBinary(t *testing.T) {
expected := &GASRecord{
GASIndexPair{
Index: 1,
GASPerBlock: *big.NewInt(123),
},
GASIndexPair{
Index: 2,
GASPerBlock: *big.NewInt(7),
},
}
testserdes.EncodeDecodeBinary(t, expected, new(GASRecord))
}
func TestGASRecord_fromStackItem(t *testing.T) {
t.Run("NotArray", func(t *testing.T) {
item := stackitem.Null{}
require.Error(t, new(GASRecord).fromStackItem(item))
})
t.Run("InvalidFormat", func(t *testing.T) {
item := stackitem.NewArray([]stackitem.Item{
stackitem.NewStruct([]stackitem.Item{
stackitem.NewBigInteger(big.NewInt(1)),
stackitem.NewBool(true),
}),
})
require.Error(t, new(GASRecord).fromStackItem(item))
})
}