diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e10e3cf9..58468b19 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21.0 - name: npm run: sudo apt -y install nodejs @@ -36,12 +36,12 @@ jobs: run: solcjs --version && ls && cd testutils/cmds/ && sudo go run compile_solidity.go && cd ../../ - name: linter - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2 + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 - name: Build run: | export GO111MODULE=on - go mod tidy -compat=1.19 + go mod tidy -compat=1.21 make qng - name: BaseTest diff --git a/core/protocol/hashornumber.go b/core/protocol/hashornumber.go index 06520e4b..91968faf 100644 --- a/core/protocol/hashornumber.go +++ b/core/protocol/hashornumber.go @@ -8,7 +8,7 @@ import ( type HashOrNumber struct { Hash *hash.Hash - Number uint64 + Number uint32 } func (hn *HashOrNumber) IsHash() bool { @@ -26,9 +26,9 @@ func NewHashOrNumber(data string) (*HashOrNumber, error) { if len(data) <= 0 { return nil, fmt.Errorf("HashOrNumber:no input data") } - num, err := strconv.Atoi(data) + num, err := strconv.ParseUint(data, 10, 32) if err == nil { - return &HashOrNumber{Number: uint64(num)}, nil + return &HashOrNumber{Number: uint32(num)}, nil } h, err := hash.NewHashFromStr(data) if err != nil { diff --git a/go.mod b/go.mod index 6a0099bd..abf8ec6d 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/ipfs/go-log/v2 v2.5.1 github.com/jessevdk/go-flags v1.4.0 github.com/jrick/logrotate v1.0.0 - github.com/libp2p/go-libp2p v0.30.0 + github.com/libp2p/go-libp2p v0.31.0 github.com/libp2p/go-libp2p-kad-dht v0.23.0 github.com/libp2p/go-libp2p-pubsub v0.9.3 github.com/magiconair/properties v1.8.5 @@ -176,8 +176,8 @@ require ( github.com/prometheus/procfs v0.9.0 // indirect github.com/protolambda/zssz v0.1.3 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-20 v0.3.2 // indirect - github.com/quic-go/quic-go v0.37.6 // indirect + github.com/quic-go/qtls-go1-20 v0.3.3 // indirect + github.com/quic-go/quic-go v0.38.1 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect diff --git a/go.sum b/go.sum index 3d49ab21..11a51830 100644 --- a/go.sum +++ b/go.sum @@ -424,6 +424,8 @@ github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFG github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= github.com/libp2p/go-libp2p v0.30.0 h1:9EZwFtJPFBcs/yJTnP90TpN1hgrT/EsFfM+OZuwV87U= github.com/libp2p/go-libp2p v0.30.0/go.mod h1:nr2g5V7lfftwgiJ78/HrID+pwvayLyqKCEirT2Y3Byg= +github.com/libp2p/go-libp2p v0.31.0 h1:LFShhP8F6xthWiBBq3euxbKjZsoRajVEyBS9snfHxYg= +github.com/libp2p/go-libp2p v0.31.0/go.mod h1:W/FEK1c/t04PbRH3fA9i5oucu5YcgrG0JVoBWT1B7Eg= github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= github.com/libp2p/go-libp2p-kad-dht v0.23.0 h1:sxE6LxLopp79eLeV695n7+c77V/Vn4AMF28AdM/XFqM= @@ -616,8 +618,12 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-20 v0.3.2 h1:rRgN3WfnKbyik4dBV8A6girlJVxGand/d+jVKbQq5GI= github.com/quic-go/qtls-go1-20 v0.3.2/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/qtls-go1-20 v0.3.3 h1:17/glZSLI9P9fDAeyCHBFSWSqJcwx1byhLwP5eUIDCM= +github.com/quic-go/qtls-go1-20 v0.3.3/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= github.com/quic-go/quic-go v0.37.6 h1:2IIUmQzT5YNxAiaPGjs++Z4hGOtIR0q79uS5qE9ccfY= github.com/quic-go/quic-go v0.37.6/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU= +github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZaE= +github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= diff --git a/testutils/evm.go b/testutils/evm.go index 039dfce0..a6917d01 100644 --- a/testutils/evm.go +++ b/testutils/evm.go @@ -9,6 +9,10 @@ import ( "crypto/ecdsa" "encoding/hex" "errors" + "log" + "math/big" + "strings" + "github.com/Qitmeer/qng/meerevm/params" "github.com/Qitmeer/qng/testutils/swap/factory" "github.com/Qitmeer/qng/testutils/swap/router" @@ -17,9 +21,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "log" - "math/big" - "strings" ) var CHAIN_ID = params.QngPrivnetChainConfig.ChainID @@ -89,7 +90,12 @@ func (w *testWallet) CreateRouter(factory, weth common.Address) (string, error) func (w *testWallet) AuthTrans(privatekeybyte []byte) (*bind.TransactOpts, error) { privateKey := crypto.ToECDSAUnsafe(privatekeybyte) - return bind.NewKeyedTransactorWithChainID(privateKey, CHAIN_ID) + authCaller, err := bind.NewKeyedTransactorWithChainID(privateKey, CHAIN_ID) + if err != nil { + return nil, err + } + authCaller.GasLimit = uint64(GAS_LIMIT) + return authCaller, nil } func (w *testWallet) CreateLegacyTx(fromPkByte []byte, to *common.Address, nonce uint64, gas uint64, val *big.Int, d []byte) (string, error) { diff --git a/testutils/evm_test.go b/testutils/evm_test.go index 4e655f6c..4f7a51bc 100644 --- a/testutils/evm_test.go +++ b/testutils/evm_test.go @@ -6,6 +6,11 @@ package testutils import ( "context" + "log" + "math/big" + "testing" + "time" + "github.com/Qitmeer/qng/core/types" "github.com/Qitmeer/qng/params" "github.com/Qitmeer/qng/testutils/swap/factory" @@ -15,10 +20,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - "log" - "math/big" - "testing" - "time" ) func TestCallErc20Contract(t *testing.T) { @@ -88,15 +89,17 @@ func TestCallErc20Contract(t *testing.T) { t.Fatal(err) } toAmount := int64(2) + toMeerAmount := big.NewInt(1e18).Mul(big.NewInt(1e18), big.NewInt(2)) for i := 0; i < 2; i++ { _, _ = h.Wallet.NewAddress() to := h.Wallet.ethAddrs[uint32(i+1)] - // send 0.01 meer - txid, err := h.Wallet.CreateLegacyTx(h.Wallet.privkeys[0], &to, 0, 21000, big.NewInt(1e16), nil) + // send 2 meer + txid, err := h.Wallet.CreateLegacyTx(h.Wallet.privkeys[0], &to, 0, 21000, toMeerAmount, nil) if err != nil { t.Fatal(err) } log.Println(i, "transfer meer:", txid) + // send 2 token tx, err := tokenCall.Transfer(authCaller, h.Wallet.ethAddrs[uint32(i+1)], big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18))) if err != nil { t.Fatal(err) @@ -115,7 +118,7 @@ func TestCallErc20Contract(t *testing.T) { if err != nil { log.Fatal(err) } - assert.Equal(t, meerBa, big.NewInt(1e16)) + assert.Equal(t, meerBa, toMeerAmount) ba, err = tokenCall.BalanceOf(&bind.CallOpts{}, h.Wallet.ethAddrs[uint32(i)]) if err != nil { t.Fatal(err) @@ -150,9 +153,18 @@ func TestCallErc20Contract(t *testing.T) { if err != nil { t.Fatal(err) } - _, err = tokenCall.TransferFrom(authCaller1, h.Wallet.ethAddrs[0], h.Wallet.ethAddrs[1], big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18))) + + tx1, err := tokenCall.TransferFrom(authCaller1, h.Wallet.ethAddrs[0], h.Wallet.ethAddrs[1], big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18))) if err == nil { - t.Fatal("Token Bug,TransferFrom without approve") + GenerateBlock(t, h, 1) + // check the transaction is ok or not + txD2, err := h.Wallet.evmClient.TransactionReceipt(context.Background(), tx1.Hash()) + if err != nil { + t.Fatal(err) + } + if txD2.Status == uint64(0x1) { + t.Fatal("Token Bug,TransferFrom without approve") + } } log.Println(err) // approve diff --git a/testutils/harness_test.go b/testutils/harness_test.go index 215256a0..45771697 100644 --- a/testutils/harness_test.go +++ b/testutils/harness_test.go @@ -5,12 +5,13 @@ package testutils_test import ( - "github.com/Qitmeer/qng/core/types" - "github.com/Qitmeer/qng/params" - . "github.com/Qitmeer/qng/testutils" "sync" "testing" "time" + + "github.com/Qitmeer/qng/core/types" + "github.com/Qitmeer/qng/params" + . "github.com/Qitmeer/qng/testutils" ) func TestHarness(t *testing.T) {