From e248ebacb0e6ac7bb9c979e4265c9a9d9ab50a28 Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Fri, 8 Sep 2023 15:44:58 +0800 Subject: [PATCH 1/8] go.mod: upgrade libp2p to v0.31.0 --- go.mod | 6 +++--- go.sum | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) 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= From 1ba9e195533678ee7cc83ad4d1fb82fd8ef283cd Mon Sep 17 00:00:00 2001 From: Jin Date: Tue, 29 Aug 2023 17:45:39 +0800 Subject: [PATCH 2/8] CI:support go1.21.0 --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e10e3cf9..047de869 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 @@ -41,7 +41,7 @@ jobs: - name: Build run: | export GO111MODULE=on - go mod tidy -compat=1.19 + go mod tidy -compat=1.21 make qng - name: BaseTest From 2e3e53fc12864e087f3c2db89ab75d0294c8c450 Mon Sep 17 00:00:00 2001 From: Jin Date: Wed, 30 Aug 2023 14:20:47 +0800 Subject: [PATCH 3/8] BUG:Incorrect conversion between integer types --- core/protocol/hashornumber.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 { From 0c936d1f86e574c4ff8fd6024d97cae75e06b247 Mon Sep 17 00:00:00 2001 From: Jin Date: Wed, 30 Aug 2023 07:58:28 +0800 Subject: [PATCH 4/8] upgrade golangci-lint --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 047de869..58468b19 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -36,7 +36,7 @@ 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: | From 576c42bc5c73444fb1818aeacc17d00434c1843f Mon Sep 17 00:00:00 2001 From: james Date: Thu, 31 Aug 2023 11:45:33 +0800 Subject: [PATCH 5/8] fix evm test --- testutils/evm.go | 14 ++++++++++---- testutils/harness_test.go | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) 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/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) { From 068107d7f8f70eaefd18352ff40ddb7874e0acec Mon Sep 17 00:00:00 2001 From: james Date: Thu, 31 Aug 2023 13:05:43 +0800 Subject: [PATCH 6/8] fix evm test --- testutils/evm_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/testutils/evm_test.go b/testutils/evm_test.go index 4e655f6c..80620001 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) { @@ -91,12 +92,13 @@ func TestCallErc20Contract(t *testing.T) { 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, big.NewInt(1e18).Mul(big.NewInt(1e18), big.NewInt(2)), 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) From 3c2041d42954de7eb33e75360f10647f92fb70bc Mon Sep 17 00:00:00 2001 From: james Date: Thu, 31 Aug 2023 13:22:01 +0800 Subject: [PATCH 7/8] fix evm test --- testutils/evm_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testutils/evm_test.go b/testutils/evm_test.go index 80620001..25fae81c 100644 --- a/testutils/evm_test.go +++ b/testutils/evm_test.go @@ -89,11 +89,12 @@ 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 2 meer - txid, err := h.Wallet.CreateLegacyTx(h.Wallet.privkeys[0], &to, 0, 21000, big.NewInt(1e18).Mul(big.NewInt(1e18), big.NewInt(2)), nil) + txid, err := h.Wallet.CreateLegacyTx(h.Wallet.privkeys[0], &to, 0, 21000, toMeerAmount, nil) if err != nil { t.Fatal(err) } @@ -117,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) From b5f5babce3acf2a7d962acb9cfd194223f221408 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 31 Aug 2023 14:42:51 +0800 Subject: [PATCH 8/8] fix evm test --- testutils/evm_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testutils/evm_test.go b/testutils/evm_test.go index 25fae81c..4f7a51bc 100644 --- a/testutils/evm_test.go +++ b/testutils/evm_test.go @@ -153,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