Skip to content

Commit

Permalink
Merge pull request #304 from aergoio/topic/update-go-dependency
Browse files Browse the repository at this point in the history
update go dependency
  • Loading branch information
rabbitprincess authored Nov 7, 2023
2 parents 6797a9f + 109e949 commit 3662150
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 123 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ MVP based, Forward compatibility, Iteration

### Prerequisites

* Go1.12.5+ - https://golang.org/dl
* Go1.19.1+ - https://golang.org/dl
* Proto Buffers - https://github.com/google/protobuf
* CMake 3.0.0 or higher - https://cmake.org

Expand Down
3 changes: 1 addition & 2 deletions config/hardfork_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions contract/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,34 @@ func TestCheckExecution(t *testing.T) {
isDeploy bool
isContract bool

expectErr error
expectErr error
expectExec bool
}{
// deploy
{version:2, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version:2, txType:types.TxType_DEPLOY, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version:2, txType:types.TxType_REDEPLOY, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_DEPLOY, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_REDEPLOY, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:true, isContract:false, expectErr:nil, expectExec:true},
{version: 2, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
{version: 2, txType: types.TxType_DEPLOY, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
{version: 2, txType: types.TxType_REDEPLOY, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_DEPLOY, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_REDEPLOY, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: true, isContract: false, expectErr: nil, expectExec: true},
// recipient is contract
{version:2, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:2, txType:types.TxType_TRANSFER, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:2, txType:types.TxType_CALL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:2, txType:types.TxType_FEEDELEGATION, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_TRANSFER, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_CALL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_FEEDELEGATION, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:true, expectErr:nil, expectExec:true},
{version: 2, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 2, txType: types.TxType_TRANSFER, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 2, txType: types.TxType_CALL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 2, txType: types.TxType_FEEDELEGATION, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_TRANSFER, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_CALL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_FEEDELEGATION, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: true, expectErr: nil, expectExec: true},
// recipient is not a contract
{version:2, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:2, txType:types.TxType_TRANSFER, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:2, txType:types.TxType_CALL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:2, txType:types.TxType_FEEDELEGATION, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:3, txType:types.TxType_NORMAL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:3, txType:types.TxType_TRANSFER, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version:3, txType:types.TxType_CALL, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:true},
{version:3, txType:types.TxType_FEEDELEGATION, amount:types.NewAmount(1,types.Aergo), payloadSize:1000, isDeploy:false, isContract:false, expectErr:nil, expectExec:false},
{version: 2, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 2, txType: types.TxType_TRANSFER, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 2, txType: types.TxType_CALL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 2, txType: types.TxType_FEEDELEGATION, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 3, txType: types.TxType_NORMAL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 3, txType: types.TxType_TRANSFER, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
{version: 3, txType: types.TxType_CALL, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: true},
{version: 3, txType: types.TxType_FEEDELEGATION, amount: types.NewAmount(1, types.Aergo), payloadSize: 1000, isDeploy: false, isContract: false, expectErr: nil, expectExec: false},
} {
do_execute, err := checkExecution(test.txType, test.amount, test.payloadSize, test.version, test.isDeploy, test.isContract)
assert.Equal(t, test.expectErr, err, "checkExecution(version:%d, txType:%d, amount:%s, payloadSize:%d)", test.version, test.txType, test.amount, test.payloadSize)
Expand Down
46 changes: 22 additions & 24 deletions contract/vm_direct/vm_direct.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package vm_direct

import (
"errors"
"math/big"
"bytes"
"encoding/json"
"context"
"os"
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"time"

"github.com/aergoio/aergo-lib/db"
"github.com/aergoio/aergo-lib/log"
"github.com/aergoio/aergo/v2/consensus"
"github.com/aergoio/aergo/v2/config"
"github.com/aergoio/aergo/v2/consensus"
"github.com/aergoio/aergo/v2/contract"
"github.com/aergoio/aergo/v2/contract/name"
"github.com/aergoio/aergo/v2/contract/system"
Expand All @@ -26,9 +26,9 @@ import (
type ChainType int

const (
ChainTypeMainNet ChainType = iota
ChainTypeTestNet
ChainTypeUnitTest
ChainTypeMainNet ChainType = iota
ChainTypeTestNet
ChainTypeUnitTest
)

const (
Expand Down Expand Up @@ -191,14 +191,13 @@ func (bc *DummyChain) SetCoinbaseAccount(address []byte) {

////////////////////////////////////////////////////////////////////////


func (bc *DummyChain) newBlockState() *state.BlockState {
bc.cBlock = &types.Block{
Header: &types.BlockHeader{
PrevBlockHash: bc.bestBlockId[:],
BlockNo: bc.bestBlockNo + 1,
Timestamp: bc.getTimestamp(),
ChainID: types.MakeChainId(bc.bestBlock.GetHeader().ChainID, bc.HardforkConfig.Version(bc.bestBlockNo + 1)),
ChainID: types.MakeChainId(bc.bestBlock.GetHeader().ChainID, bc.HardforkConfig.Version(bc.bestBlockNo+1)),
},
}
return state.NewBlockState(
Expand All @@ -208,7 +207,6 @@ func (bc *DummyChain) newBlockState() *state.BlockState {
)
}


func (bc *DummyChain) ExecuteTxs(txs []*types.Tx) ([]*types.Receipt, error) {

ex, err := newBlockExecutor(bc, txs)
Expand Down Expand Up @@ -254,7 +252,7 @@ func newBlockExecutor(bc *DummyChain, txs []*types.Tx) (*blockExecutor, error) {

blockState.SetGasPrice(system.GetGasPriceFromState(blockState))

blockState.Receipts().SetHardFork(bc.HardforkConfig, bc.bestBlockNo + 1)
blockState.Receipts().SetHardFork(bc.HardforkConfig, bc.bestBlockNo+1)

return &blockExecutor{
BlockState: blockState,
Expand All @@ -265,7 +263,7 @@ func newBlockExecutor(bc *DummyChain, txs []*types.Tx) (*blockExecutor, error) {
//validatePost: func() error {
// return cs.validator.ValidatePost(blockState.GetRoot(), blockState.Receipts(), block)
//},
bi: bi,
bi: bi,
}, nil

}
Expand Down Expand Up @@ -448,21 +446,21 @@ func executeTx(
senderState.Balance = amount.Bytes()
}
}
case types.TxType_FEEDELEGATION:
if balance.Cmp(amount) <= 0 {
// set the balance as = amount
senderState.Balance = amount.Bytes()
}
case types.TxType_FEEDELEGATION:
if balance.Cmp(amount) <= 0 {
// set the balance as = amount
senderState.Balance = amount.Bytes()
}
}

err = tx.ValidateWithSenderState(senderState, bs.GasPrice, bi.ForkVersion)
if err != nil {
err = fmt.Errorf("%w: balance %s, amount %s, gasPrice %s, block %v, txhash: %s",
err,
sender.Balance().String(),
tx.GetBody().GetAmountBigInt().String(),
bs.GasPrice.String(),
bi.No, enc.ToString(tx.GetHash()))
err = fmt.Errorf("%w: balance %s, amount %s, gasPrice %s, block %v, txhash: %s",
err,
sender.Balance().String(),
tx.GetBody().GetAmountBigInt().String(),
bs.GasPrice.String(),
bi.No, enc.ToString(tx.GetHash()))
return err
}

Expand Down
48 changes: 25 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ require (
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/golang-lru v0.5.1
github.com/improbable-eng/grpc-web v0.9.6
github.com/json-iterator/go v1.1.9
github.com/improbable-eng/grpc-web v0.15.0
github.com/json-iterator/go v1.1.10
github.com/libp2p/go-addr-util v0.0.1
github.com/libp2p/go-libp2p v0.4.0
github.com/libp2p/go-libp2p-core v0.2.3
Expand All @@ -33,7 +33,7 @@ require (
github.com/mr-tron/base58 v1.1.2
github.com/multiformats/go-multiaddr v0.1.1
github.com/multiformats/go-multiaddr-net v0.1.0
github.com/opentracing/opentracing-go v1.0.2
github.com/opentracing/opentracing-go v1.1.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.1
github.com/sanity-io/litter v1.5.5
Expand All @@ -42,28 +42,30 @@ require (
github.com/spf13/viper v1.5.0
github.com/stretchr/testify v1.8.4
github.com/willf/bloom v2.0.3+incompatible
golang.org/x/crypto v0.11.0
google.golang.org/grpc v1.56.2
golang.org/x/crypto v0.14.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/Workiva/go-datastructures v1.0.50 // indirect
github.com/beorn7/perks v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v3 v3.2103.2 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/funkygao/assert v0.0.0-20160929004900-4a267e33bc79 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 // indirect
github.com/huin/goupnp v1.0.0 // indirect
Expand Down Expand Up @@ -122,11 +124,11 @@ require (
github.com/pelletier/go-toml v1.2.1-0.20180930205832-81a861c69d25 // indirect
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.0.0 // indirect
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect
github.com/prometheus/common v0.4.1 // indirect
github.com/prometheus/procfs v0.0.2 // indirect
github.com/rs/cors v1.6.0 // indirect
github.com/prometheus/client_golang v1.7.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.15.0 // indirect
github.com/prometheus/procfs v0.3.0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/serialx/hashring v0.0.0-20190515033939-7706f26af194 // indirect
github.com/smola/gocompat v0.2.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
Expand All @@ -145,18 +147,18 @@ require (
github.com/willf/bitset v1.1.10 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.opencensus.io v0.22.5 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc/examples v0.0.0-20230724170852-2aa261560586 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
)

replace github.com/Sirupsen/logrus => github.com/sirupsen/logrus v1.8.1
Loading

0 comments on commit 3662150

Please sign in to comment.