Merge pull request #1822 from nspcc-dev/fix/compilerequals

Convert boolean values in `vm/emit`
This commit is contained in:
Roman Khimov 2021-03-09 13:58:03 +03:00 committed by GitHub
commit f35acffabf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 22 deletions

View file

@ -85,7 +85,7 @@ func TestNEP17Balance(t *testing.T) {
}
e.checkNextLine(t, "^\\s*$")
addr4, err := address.StringToUint160("NbxpLNCCSWZ9BkYpCYT8NfN1uoxq9Rfbrn") // deployed verify.go contract
addr4, err := address.StringToUint160("NWTDxsHVde5qSjRkTRUAg6i8xC3JSWEC9k") // deployed verify.go contract
require.NoError(t, err)
e.checkNextLine(t, "^Account "+address.Uint160ToString(addr4))
e.checkEOF(t)

View file

@ -61,7 +61,7 @@
"isdefault": false
},
{
"address" : "NbxpLNCCSWZ9BkYpCYT8NfN1uoxq9Rfbrn",
"address" : "NWTDxsHVde5qSjRkTRUAg6i8xC3JSWEC9k",
"key" : "6PYXDze5Ak4HahYKygcNzk6n65ACjWdDCYLSuKgA5KG8vyMJSFboUNSiPD",
"label" : "",
"contract" : {

View file

@ -361,3 +361,15 @@ func TestShortCircuit(t *testing.T) {
eval(t, src, big.NewInt(17))
})
}
func TestEmitBoolean(t *testing.T) {
src := `package foo
func Main() int {
a := true
if (a == true) == true {
return 42
}
return 11
}`
eval(t, src, big.NewInt(42))
}

View file

@ -209,7 +209,7 @@ func TestBoolAssign(t *testing.T) {
return x
}
`
eval(t, src, big.NewInt(1))
eval(t, src, true)
}
func TestBoolCompare(t *testing.T) {

View file

@ -46,7 +46,7 @@ func TestMultipleDirFileImport(t *testing.T) {
return ok
}
`
eval(t, src, big.NewInt(1))
eval(t, src, true)
}
func TestImportNameSameAsOwn(t *testing.T) {

View file

@ -304,6 +304,7 @@ func initBasicChain(t *testing.T, bc *Blockchain) {
t.Logf("native NEO hash: %v", neoHash)
t.Logf("native Policy hash: %v", policyHash)
t.Logf("native Notary hash: %v", notaryHash)
t.Logf("Block0 hash: %s", bc.GetHeaderHash(0).StringLE())
priv0 := testchain.PrivateKeyByID(0)
priv0ScriptHash := priv0.GetScriptHash()

View file

@ -59,9 +59,9 @@ type rpcTestCase struct {
check func(t *testing.T, e *executor, result interface{})
}
const testContractHash = "c6436aab21ebd15279b85af8d7b5808d38455b0a"
const deploymentTxHash = "050e2189d7cd7b719d9c4bbc525d3edcd89ffedb28cc974862d17dda14377612"
const genesisBlockHash = "41d1099030004d60f3b4b7ffe00bf184e84fac3a39ee7136c761e005f0186d93"
const testContractHash = "500858b96054d3c302078882c30e76915aac1c83"
const deploymentTxHash = "fbea49056332ecf1482568e24ed745151ed3fcacbb59afc22d9baff5346e6257"
const genesisBlockHash = "0542f4350c6e236d0509bcd98188b0034bfbecc1a0c7fcdb8e4295310d468b70"
const verifyContractHash = "03ffc0897543b9b709e0f8cab4a7682dae0ba943"
const verifyContractAVM = "570300412d51083021700c14aa8acf859d4fe402b34e673f2156821796a488ebdb30716813cedb2869db289740"
@ -1598,7 +1598,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) {
},
{
Asset: e.chain.UtilityTokenHash(),
Amount: "78994306100",
Amount: "78994294100",
LastUpdated: 8,
}},
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),

Binary file not shown.

View file

@ -1,7 +1,6 @@
package testdata
import (
"github.com/nspcc-dev/neo-go/pkg/interop/convert"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/util"
)
@ -11,5 +10,5 @@ import (
func Verify() bool {
tx := runtime.GetScriptContainer()
addr := util.FromAddress("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc")
return util.Equals(convert.ToByteArray(tx.Sender), convert.ToByteArray(addr))
return util.Equals(string(tx.Sender), string(addr))
}

View file

@ -33,9 +33,9 @@ func Opcodes(w *io.BinWriter, ops ...opcode.Opcode) {
func Bool(w *io.BinWriter, ok bool) {
if ok {
Opcodes(w, opcode.PUSHT)
return
}
} else {
Opcodes(w, opcode.PUSHF)
}
Instruction(w, opcode.CONVERT, []byte{byte(stackitem.BooleanT)})
}

View file

@ -9,6 +9,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -151,15 +152,17 @@ func TestEmitArray(t *testing.T) {
assert.EqualValues(t, 2, res[1])
assert.EqualValues(t, []byte{0xCA, 0xFE}, res[2:4])
assert.EqualValues(t, opcode.PUSHT, res[4])
assert.EqualValues(t, opcode.PUSHDATA1, res[5])
assert.EqualValues(t, 3, res[6])
assert.EqualValues(t, []byte("str"), res[7:10])
assert.EqualValues(t, opcode.PUSH1, res[10])
assert.EqualValues(t, opcode.PUSHNULL, res[11])
assert.EqualValues(t, opcode.PUSH2, res[12])
assert.EqualValues(t, opcode.PUSH1, res[13])
assert.EqualValues(t, opcode.CONVERT, res[5])
assert.EqualValues(t, stackitem.BooleanT, res[6])
assert.EqualValues(t, opcode.PUSHDATA1, res[7])
assert.EqualValues(t, 3, res[8])
assert.EqualValues(t, []byte("str"), res[9:12])
assert.EqualValues(t, opcode.PUSH1, res[12])
assert.EqualValues(t, opcode.PUSHNULL, res[13])
assert.EqualValues(t, opcode.PUSH2, res[14])
assert.EqualValues(t, opcode.PACK, res[15])
assert.EqualValues(t, opcode.PUSH1, res[15])
assert.EqualValues(t, opcode.PUSH2, res[16])
assert.EqualValues(t, opcode.PACK, res[17])
})
t.Run("empty", func(t *testing.T) {
@ -181,8 +184,12 @@ func TestEmitBool(t *testing.T) {
Bool(buf.BinWriter, true)
Bool(buf.BinWriter, false)
result := buf.Bytes()
assert.Equal(t, opcode.Opcode(result[0]), opcode.PUSH1)
assert.Equal(t, opcode.Opcode(result[1]), opcode.PUSH0)
assert.EqualValues(t, opcode.PUSH1, result[0])
assert.EqualValues(t, opcode.CONVERT, result[1])
assert.EqualValues(t, stackitem.BooleanT, result[2])
assert.EqualValues(t, opcode.PUSH0, result[3])
assert.EqualValues(t, opcode.CONVERT, result[4])
assert.EqualValues(t, stackitem.BooleanT, result[5])
}
func TestEmitOpcode(t *testing.T) {