From 9b8e66235752d5334a10023f9e00218904d746e8 Mon Sep 17 00:00:00 2001 From: Jhih-Ming Huang Date: Wed, 3 Apr 2019 17:17:21 +0800 Subject: core: vm: sqlvm: ast: decimal decode for bool --- core/vm/sqlvm/ast/types.go | 5 +++++ core/vm/sqlvm/runtime/instructions_test.go | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/vm/sqlvm/ast/types.go b/core/vm/sqlvm/ast/types.go index 9bb48bc65..5f7f1b886 100644 --- a/core/vm/sqlvm/ast/types.go +++ b/core/vm/sqlvm/ast/types.go @@ -385,6 +385,11 @@ func DecimalDecode(dt DataType, b []byte) (decimal.Decimal, error) { return decimalDecode(true, b), nil case DataTypeMajorUint: return decimalDecode(false, b), nil + case DataTypeMajorBool: + if b[0] == 0 { + return dec.False, nil + } + return dec.True, nil } switch { case major.IsFixedRange(): diff --git a/core/vm/sqlvm/runtime/instructions_test.go b/core/vm/sqlvm/runtime/instructions_test.go index b679c366f..576a7783a 100644 --- a/core/vm/sqlvm/runtime/instructions_test.go +++ b/core/vm/sqlvm/runtime/instructions_test.go @@ -14,6 +14,7 @@ import ( "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/core/vm/sqlvm/ast" "github.com/dexon-foundation/dexon/core/vm/sqlvm/common" + dec "github.com/dexon-foundation/dexon/core/vm/sqlvm/common/decimal" "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors" "github.com/dexon-foundation/dexon/core/vm/sqlvm/schema" "github.com/dexon-foundation/dexon/crypto" @@ -99,6 +100,16 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address, major: ast.DataTypeMajorUint, minor: ast.DataTypeMinor(7), }, + { + Raw: Raw{ + Value: dec.False, + Bytes: nil, + }, + slotShift: 0, + byteShift: 10, + major: ast.DataTypeMajorBool, + minor: ast.DataTypeMinor(0), + }, { Raw: Raw{ Bytes: []byte("Hello, world!"), @@ -158,7 +169,7 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address, } // set dynamic bytes data - longDBytesLoc := 5 + longDBytesLoc := 6 longRaw := raws[longDBytesLoc] hash.SetBytes(longRaw.Bytes) ptr = storage.ShiftHashUint64(head, uint64(longRaw.slotShift)) -- cgit v1.2.3