Skip to content

Commit

Permalink
Merge pull request #523 from dindinw/testnet
Browse files Browse the repository at this point in the history
go.mod: upgrade libp2p to v0.31.0 && cheery-pick #508 #510 #512 #513 from main branch
  • Loading branch information
dindinw authored Sep 8, 2023
2 parents 6a36fb9 + b5f5bab commit 5227cc4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions core/protocol/hashornumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type HashOrNumber struct {
Hash *hash.Hash
Number uint64
Number uint32
}

func (hn *HashOrNumber) IsHash() bool {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
14 changes: 10 additions & 4 deletions testutils/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 21 additions & 9 deletions testutils/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions testutils/harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5227cc4

Please sign in to comment.