Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/platon/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func runPlatON(t *testing.T, args ...string) *testplaton {
if tt.Datadir == "" {
tt.Datadir = tmpdir(t)
tt.Cleanup = func() { os.RemoveAll(tt.Datadir) }
args = append([]string{"-datadir", tt.Datadir}, args...)
args = append([]string{"--datadir", tt.Datadir}, args...)
// Remove the temporary datadir if something fails below.
defer func() {
if t.Failed() {
Expand Down
2 changes: 0 additions & 2 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ func CalcGasLimit(parent *types.Block, gasFloor /*, gasCeil*/ uint64) uint64 {
gasFloor = gasCeil
}

// contrib = (parentGasUsed * 3 / 2) / 256
contrib := (parent.GasUsed() + parent.GasUsed()/2) / params.GasLimitBoundDivisor

// decay = parentGasLimit / 256 -1
decay := parent.GasLimit()/params.GasLimitBoundDivisor - 1

/*
Expand Down
4 changes: 0 additions & 4 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"encoding/json"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -268,9 +267,6 @@ func testReorg(t *testing.T, first, second []int64, td int64, full bool) {
if full {
prev := blockchain.engine.CurrentBlock()

b, _ := json.Marshal(prev)
fmt.Println("current block", string(b))

for block := blockchain.engine.GetBlockByHash(prev.ParentHash()); block != nil; prev, block = block, blockchain.engine.GetBlockByHash(block.ParentHash()) {

//for block := blockchain.GetBlockByNumber(blockchain.CurrentBlock().NumberU64() - 1); block.NumberU64() != 0; prev, block = block, blockchain.GetBlockByNumber(block.NumberU64()-1) {
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ func TestTransactionQueueTimeLimitingNoLocals(t *testing.T) {
func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
// Reduce the eviction interval to a testable amount
defer func(old time.Duration) { evictionInterval = old }(evictionInterval)
evictionInterval = time.Second
evictionInterval = time.Millisecond * 100

// Create the pool to test the non-expiration enforcement
config := testTxPoolConfig
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/PlatONnetwork/PlatON-Go

go 1.13
go 1.14

require (
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
Expand Down
42 changes: 32 additions & 10 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"regexp"
"strings"
"sync"
"sync/atomic"
"syscall"
"testing"
"text/template"
"time"
Expand All @@ -50,12 +52,17 @@ type TestCmd struct {
stdout *bufio.Reader
stdin io.WriteCloser
stderr *testlogger
// Err will contain the process exit error or interrupt signal error
Err error
}

var id int32

// Run exec's the current binary using name as argv[0] which will trigger the
// reexec init function for that name (e.g. "platon-test" in cmd/platon/run_test.go)
func (tt *TestCmd) Run(name string, args ...string) {
tt.stderr = &testlogger{t: tt.T}
id := atomic.AddInt32(&id, 1)
tt.stderr = &testlogger{t: tt.T, name: fmt.Sprintf("%d", id)}
tt.cmd = &exec.Cmd{
Path: reexec.Self(),
Args: append([]string{name}, args...),
Expand All @@ -74,7 +81,7 @@ func (tt *TestCmd) Run(name string, args ...string) {
}
}

// InputLine writes the given text to the childs stdin.
// InputLine writes the given text to the child's stdin.
// This method can also be called from an expect template, e.g.:
//
// platon.expect(`Passphrase: {{.InputLine "password"}}`)
Expand Down Expand Up @@ -131,12 +138,12 @@ func (tt *TestCmd) matchExactOutput(want []byte) error {

for i := 0; i < n; i++ {
if want[i] != buf[i] {
return fmt.Errorf("Output mismatch at ◊:\n---------------- (stdout text)\n%s◊%s\n---------------- (expected text)\n%s",
return fmt.Errorf("output mismatch at ◊:\n---------------- (stdout text)\n%s◊%s\n---------------- (expected text)\n%s",
buf[:i], buf[i:n], want)
}
}
if n < len(want) {
return fmt.Errorf("Not enough output, got until ◊:\n---------------- (stdout text)\n%s\n---------------- (expected text)\n%s◊%s",
return fmt.Errorf("not enough output, got until ◊:\n---------------- (stdout text)\n%s\n---------------- (expected text)\n%s◊%s",
buf, want[:n], want[n:])
}
}
Expand Down Expand Up @@ -189,11 +196,25 @@ func (tt *TestCmd) ExpectExit() {
}

func (tt *TestCmd) WaitExit() {
tt.cmd.Wait()
tt.Err = tt.cmd.Wait()
}

func (tt *TestCmd) Interrupt() {
tt.cmd.Process.Signal(os.Interrupt)
tt.Err = tt.cmd.Process.Signal(os.Interrupt)
}

// ExitStatus exposes the process' OS exit code
// It will only return a valid value after the process has finished.
func (tt *TestCmd) ExitStatus() int {
if tt.Err != nil {
exitErr := tt.Err.(*exec.ExitError)
if exitErr != nil {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus()
}
}
}
return 0
}

// StderrText returns any stderr output written so far.
Expand Down Expand Up @@ -228,16 +249,17 @@ func (tt *TestCmd) withKillTimeout(fn func()) {
// testlogger logs all written lines via t.Log and also
// collects them for later inspection.
type testlogger struct {
t *testing.T
mu sync.Mutex
buf bytes.Buffer
t *testing.T
mu sync.Mutex
buf bytes.Buffer
name string
}

func (tl *testlogger) Write(b []byte) (n int, err error) {
lines := bytes.Split(b, []byte("\n"))
for _, line := range lines {
if len(line) > 0 {
tl.t.Logf("(stderr) %s", line)
tl.t.Logf("(stderr:%v) %s", tl.name, line)
}
}
tl.mu.Lock()
Expand Down
18 changes: 5 additions & 13 deletions x/plugin/restricting_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,10 @@ func (rp *RestrictingPlugin) AddRestrictingRecord(from, account common.Address,
return err
}
// pre-check
{

if totalAmount.Cmp(big.NewInt(1e18)) < 0 {
rp.log.Error("Failed to AddRestrictingRecord: total restricting amount need more than 1 LAT",
"from", from, "amount", totalAmount)
return restricting.ErrLockedAmountTooLess
}

if state.GetBalance(from).Cmp(totalAmount) < 0 {
rp.log.Error("Failed to AddRestrictingRecord: balance of the sender is not enough",
"total", totalAmount, "balance", state.GetBalance(from))
return restricting.ErrBalanceNotEnough
}
if state.GetBalance(from).Cmp(totalAmount) < 0 {
rp.log.Error("Failed to AddRestrictingRecord: balance of the sender is not enough",
"total", totalAmount, "balance", state.GetBalance(from))
return restricting.ErrBalanceNotEnough
}
if txhash == common.ZeroHash {
return nil
Expand Down Expand Up @@ -584,6 +575,7 @@ func (rp *RestrictingPlugin) releaseRestricting(epoch uint64, state xcom.StateDB
rp.log.Debug("Call releaseRestricting: begin to release record", "index", index, "account", account,
"restrictInfo", restrictInfo, "releaseAmount", releaseAmount)

//if NeedRelease>0,CachePlanAmount = AdvanceAmount
if restrictInfo.NeedRelease.Cmp(common.Big0) > 0 {
restrictInfo.NeedRelease.Add(restrictInfo.NeedRelease, releaseAmount)
} else {
Expand Down
10 changes: 1 addition & 9 deletions x/plugin/restricting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,13 @@ func TestRestrictingPlugin_AddRestrictingRecord(t *testing.T) {
expect error
des string
}
var largePlans, largeMountPlans, notEnough []restricting.RestrictingPlan
var largePlans, largeMountPlans []restricting.RestrictingPlan
for i := 0; i < 40; i++ {
largePlans = append(largePlans, restricting.RestrictingPlan{1, big.NewInt(1e15)})
}
for i := 0; i < 4; i++ {
largeMountPlans = append(largeMountPlans, restricting.RestrictingPlan{1, big.NewInt(1e18)})
}
for i := 0; i < 4; i++ {
notEnough = append(notEnough, restricting.RestrictingPlan{1, big.NewInt(1e16)})
}
x := []testtmp{
{
input: make([]restricting.RestrictingPlan, 0),
Expand Down Expand Up @@ -160,11 +157,6 @@ func TestRestrictingPlugin_AddRestrictingRecord(t *testing.T) {
expect: restricting.ErrBalanceNotEnough,
des: "amount not enough",
},
{
input: notEnough,
expect: restricting.ErrLockedAmountTooLess,
des: "amount too small",
},
}
for _, value := range x {
if err := plugin.AddRestrictingRecord(sender, addrArr[0], 20, common.ZeroHash, value.input, mockDB, RestrictingTxHash); err != value.expect {
Expand Down
8 changes: 4 additions & 4 deletions x/xcom/common_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ const (
var (
one, _ = new(big.Int).SetString("1000000000000000000", 10)

// 10 ATP
// 10 LAT
DelegateLowerLimit, _ = new(big.Int).SetString("10000000000000000000", 10)

// 1W ATP
// 1W LAT
DelegateUpperLimit, _ = new(big.Int).SetString("10000000000000000000000", 10)

// hard code genesis staking balance
Expand All @@ -80,7 +80,7 @@ var (

// 10W
StakeLowerLimit, _ = new(big.Int).SetString("100000000000000000000000", 10)
// 1000W ATP
// 1000W LAT
StakeUpperLimit, _ = new(big.Int).SetString("10000000000000000000000000", 10)

FloorMinimumRelease = new(big.Int).Mul(new(big.Int).SetUint64(100), one)
Expand Down Expand Up @@ -187,7 +187,7 @@ func getDefaultEMConfig(netId int8) *EconomicModel {
cdfundBalance *big.Int
)

// 3.31811981 thousand millions LAT
// 3.22361981 thousand millions LAT
if cdfundBalance, ok = new(big.Int).SetString("322361981000000000000000000", 10); !ok {
return nil
}
Expand Down