diff --git a/cmd/platon/run_test.go b/cmd/platon/run_test.go index 3726c5ad40..428ad96901 100644 --- a/cmd/platon/run_test.go +++ b/cmd/platon/run_test.go @@ -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() { diff --git a/core/block_validator.go b/core/block_validator.go index 2a7f540c2f..2e5ae9590b 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -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 /* diff --git a/core/blockchain_test.go b/core/blockchain_test.go index ec272a6fb6..e7c71f356f 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -17,7 +17,6 @@ package core import ( - "encoding/json" "fmt" "math/big" "testing" @@ -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) { diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 658d7eae6b..3692e57dc8 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -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 diff --git a/go.mod b/go.mod index 6b515ad144..e738ad5b2f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index f06a14d0a4..43d41a2ca5 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -27,6 +27,8 @@ import ( "regexp" "strings" "sync" + "sync/atomic" + "syscall" "testing" "text/template" "time" @@ -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...), @@ -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"}}`) @@ -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:]) } } @@ -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. @@ -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() diff --git a/x/plugin/restricting_plugin.go b/x/plugin/restricting_plugin.go index ecec6d9b49..c692a731a1 100644 --- a/x/plugin/restricting_plugin.go +++ b/x/plugin/restricting_plugin.go @@ -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 @@ -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 { diff --git a/x/plugin/restricting_plugin_test.go b/x/plugin/restricting_plugin_test.go index 7374bd6ef3..1b1d158a9f 100644 --- a/x/plugin/restricting_plugin_test.go +++ b/x/plugin/restricting_plugin_test.go @@ -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), @@ -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 { diff --git a/x/xcom/common_config.go b/x/xcom/common_config.go index 365f99dd26..e3aebfb9ce 100644 --- a/x/xcom/common_config.go +++ b/x/xcom/common_config.go @@ -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 @@ -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) @@ -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 }