Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/zzhang/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed Jan 19, 2019
2 parents 48d0311 + 1a3a030 commit ff9cb1b
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 70 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -32,14 +32,14 @@ matrix:
services:
- docker
before_install:
- docker pull iostio/iost-dev:2.1.0
- docker pull iostio/iost-dev:2.3.0
- git lfs install
before_script:
- git lfs pull
script:
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.1.0 make build
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.1.0 make lint
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.1.0 make test
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.3.0 make build
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.3.0 make lint
- docker run -it --rm -v $(pwd):/gopath/src/github.com/iost-official/go-iost iostio/iost-dev:2.3.0 make test
after_success:
- bash <(curl -s https://codecov.io/bash)
- os: linux
Expand All @@ -49,7 +49,7 @@ matrix:
services:
- docker
before_install:
- docker pull iostio/iost-dev:2.1.0
- docker pull iostio/iost-dev:2.3.0
- git lfs install
before_script:
- git lfs pull
Expand All @@ -63,7 +63,7 @@ matrix:
services:
- docker
before_install:
- docker pull iostio/iost-dev:2.1.0
- docker pull iostio/iost-dev:2.3.0
- git lfs install
- pyenv global 3.6 && pip install awscli
- go get -u -v github.com/kubernetes-sigs/aws-iam-authenticator/cmd/aws-iam-authenticator
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
## Everest v2.3.0

Sat Jan 19 17:25:28 CST 2019

- Increase minimum GasLimit of transaction from 5000 to 6000.
- RPC: add "voteInfos" to getAccount api
- Complete vote, dividend test
- iwallet remove npm package dependencies
- Add exchange.iost system contract, used for creating accounts and transferring

## Everest v2.2.1

Sat Jan 12 20:36:05 CST 2019
Expand Down
2 changes: 1 addition & 1 deletion Makefile
@@ -1,6 +1,6 @@
GO = go

VERSION = 2.2.1
VERSION = 2.3.0
COMMIT = $(shell git rev-parse --short HEAD)
PROJECT = github.com/iost-official/go-iost
DOCKER_IMAGE = iostio/iost-node:$(VERSION)-$(COMMIT)
Expand Down
4 changes: 0 additions & 4 deletions config/genesis/contract/account.js
@@ -1,8 +1,4 @@
class Account {
constructor() {

}

init() {

}
Expand Down
2 changes: 0 additions & 2 deletions config/genesis/contract/base.js
Expand Up @@ -3,8 +3,6 @@ const voteStatInterval = 2000;
const issueInterval = 288000;

class Base {
constructor() {
}
init() {
this._put("execBlockNumber", 0);
}
Expand Down
3 changes: 0 additions & 3 deletions config/genesis/contract/bonus.js
Expand Up @@ -3,9 +3,6 @@ const totalSupply = 90000000000;
const blockContribRadio = new Float64("9.6568764571e-11");

class BonusContract {
constructor() {
}

init() {
this._initContribute();
this._put("blockContrib", "1.98779440");
Expand Down
31 changes: 22 additions & 9 deletions config/genesis/contract/exchange.js
@@ -1,7 +1,21 @@
const ADMIN_PERMISSION = "active";

class Exchange {
init() {
}

can_update(data) {
this._requireAuth("admin", ADMIN_PERMISSION);
return true;
}

_requireAuth(account, permission) {
const ret = blockchain.requireAuth(account, permission);
if (ret !== true) {
throw new Error("require auth failed. ret = " + ret);
}
}

/**
*
* @param tokenSym {string} token symbol
Expand All @@ -15,21 +29,20 @@ class Exchange {
* transfer("iost", "", "100.1", "create:newUser2:OWNERKEY:ACTIVEKEY")
*/
transfer(tokenSym, to, amount, memo) {
const minAmount = 100;
const initialRAM = 1000;
const initialGasPledged = 10;

let bamount = new BigNumber(amount);
if (bamount.lt(minAmount)) {
throw new Error("transfer amount should be greater or equal to " + minAmount);
}

let from = blockchain.publisher();
if (to !== "") {
// transfer to an exist account
blockchain.call("token.iost", "transfer", [tokenSym, from, to, amount, memo]);

} else if (to == "") {
const minAmount = 100;
const initialRAM = 1000;
const initialGasPledged = 10;
let bamount = new BigNumber(amount);
if (bamount.lt(minAmount)) {
throw new Error("transfer amount should be greater or equal to " + minAmount);
}

if (memo.startsWith("create:")) {
if (tokenSym !== "iost") {
throw new Error("must transfer iost if you want to create a new account");
Expand Down
6 changes: 5 additions & 1 deletion config/genesis/contract/exchange.js.abi
Expand Up @@ -2,6 +2,10 @@
"lang": "javascript",
"version": "1.0.0",
"abi": [
{
"name": "can_update",
"args": ["string"]
},
{
"name": "transfer",
"args": [
Expand All @@ -15,4 +19,4 @@
]
}
]
}
}
3 changes: 0 additions & 3 deletions config/genesis/contract/ram.js
Expand Up @@ -2,9 +2,6 @@ const transferPermission = "transfer";
const updatePermission = "active";

class RAMContract {
constructor() {
}

init() {
}

Expand Down
3 changes: 0 additions & 3 deletions config/genesis/contract/vote.js
Expand Up @@ -9,9 +9,6 @@ const votePermission = "active";
const statPermission = "active";

class VoteContract {
constructor() {
}

init() {
this._put("currentProducerList", []);
this._put("pendingProducerList", []);
Expand Down
3 changes: 0 additions & 3 deletions config/genesis/contract/vote_common.js
Expand Up @@ -14,9 +14,6 @@ const TRUE = 1;
const FALSE = 0;

class VoteCommonContract {
constructor() {
}

init() {
this._put("current_id", "0");
}
Expand Down
9 changes: 9 additions & 0 deletions itest/client.go
Expand Up @@ -251,6 +251,15 @@ func (c *Client) ContractTransfer(cid string, sender, recipient *Account, amount
return err
}

// ExchangeTransfer will contract transfer token by sending transaction
func (c *Client) ExchangeTransfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error {
memo := make([]byte, memoSize)
rand.Read(memo)
memoStr := base64.StdEncoding.EncodeToString(memo)
_, err := c.CallAction(check, sender, "exchange.iost", "transfer", token, recipient.ID, amount, memoStr[:memoSize])
return err
}

// CallAction send a tx with given actions
func (c *Client) CallAction(check bool, sender *Account, contractName, actionName string, args ...interface{}) (string, error) {
argsBytes, err := json.Marshal(args)
Expand Down
5 changes: 5 additions & 0 deletions itest/command/run/benchmark.go
Expand Up @@ -48,6 +48,7 @@ const (
GasTx
RAMTx
AccountTx
ExchangeTransferTx
)

// BenchmarkAction is the action of benchmark.
Expand Down Expand Up @@ -85,6 +86,8 @@ var BenchmarkAction = func(c *cli.Context) error {
itest.InitAmount = "10"
itest.InitPledge = "20"
itest.InitRAM = "1000"
case "e", "exchange":
txType = ExchangeTransferTx
default:
return fmt.Errorf("wrong transaction type: %v", txType)
}
Expand Down Expand Up @@ -126,6 +129,8 @@ var BenchmarkAction = func(c *cli.Context) error {
var accs []*itest.Account
accs, err = it.CreateAccountN(tps, true, false)
num = len(accs)
} else if txType == ExchangeTransferTx {
num, err = it.ExchangeTransferN(tps, accounts, memoSize, false)
} else {
panic("invalid tx type, check --type flag")
}
Expand Down
63 changes: 62 additions & 1 deletion itest/itest.go
Expand Up @@ -2,11 +2,12 @@ package itest

import (
"fmt"
"github.com/iost-official/go-iost/core/contract"
"math"
"math/rand"
"strconv"

"github.com/iost-official/go-iost/core/contract"

"github.com/iost-official/go-iost/ilog"
"reflect"
)
Expand Down Expand Up @@ -481,6 +482,53 @@ func (t *ITest) ContractTransferN(cid string, num int, accounts []*Account, memo
return
}

// ExchangeTransferN will send n contract transfer transaction concurrently
func (t *ITest) ExchangeTransferN(num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error) {
ilog.Infof("Sending %v exchange transfer transaction...", num)

res := make(chan interface{})
go func() {
sem := make(semaphore, concurrentNum)
for i := 0; i < num; i++ {
sem.acquire()
go func(res chan interface{}) {
defer sem.release()
A := accounts[rand.Intn(len(accounts))]
balance, _ := strconv.ParseFloat(A.balance, 64)
for balance < 1 {
A = accounts[rand.Intn(len(accounts))]
balance, _ = strconv.ParseFloat(A.balance, 64)
}
B := accounts[rand.Intn(len(accounts))]
amount := float64(rand.Int63n(int64(math.Min(10000, balance*100)))+1) / 100

ilog.Debugf("Contract transfer %v -> %v, amount: %v", A.ID, B.ID, fmt.Sprintf("%0.8f", amount))
err := t.ExchangeTransfer(A, B, fmt.Sprintf("%0.8f", amount), memoSize, check)

if err == nil {
A.AddBalance(-amount)
B.AddBalance(amount)
}
res <- err
}(res)
}
}()

for i := 0; i < num; i++ {
switch value := (<-res).(type) {
case error:
if firstErr == nil {
firstErr = fmt.Errorf("failed to send contract transfer transactions: %v", value)
}
default:
successNum++
}
}

ilog.Infof("Sent %v/%v contract transfer transactions", successNum, num)
return
}

// CheckAccounts will check account info by getting account info
func (t *ITest) CheckAccounts(a []*Account) error {
ilog.Infof("Get %v accounts info...", len(a))
Expand Down Expand Up @@ -551,6 +599,19 @@ func (t *ITest) ContractTransfer(cid string, sender, recipient *Account, amount
return nil
}

// ExchangeTransfer will contract transfer token from sender to recipient
func (t *ITest) ExchangeTransfer(sender, recipient *Account, amount string, memoSize int, check bool) error {
cIndex := rand.Intn(len(t.clients))
client := t.clients[cIndex]

err := client.ExchangeTransfer(sender, recipient, "iost", amount, memoSize, check)
if err != nil {
return err
}

return nil
}

// vote will vote producer from sender to recipient
func (t *ITest) vote(sender *Account, recipient, amount string) error {
cIndex := rand.Intn(len(t.clients))
Expand Down
3 changes: 0 additions & 3 deletions test/gas/test_data/base_op.js
@@ -1,9 +1,6 @@
'use strict';

class BaseOp {
constructor() {
}

doThrowStatement(num) {
for (let i = 0; i < num; i++) {
try {
Expand Down
3 changes: 0 additions & 3 deletions test/gas/test_data/empty_op.js
@@ -1,9 +1,6 @@
'use strict';

class EmptyOp {
constructor() {
}

doStartUp() {
}

Expand Down
3 changes: 0 additions & 3 deletions test/gas/test_data/lib_op.js
@@ -1,9 +1,6 @@
'use strict';

class LibOp {
constructor() {
}

// String
doStringCharAt(num) {
for (let i = 0; i < num; i++) {
Expand Down
3 changes: 0 additions & 3 deletions test/gas/test_data/storage_op.js
@@ -1,9 +1,6 @@
'use strict';

class StorageOp {
constructor() {
}

doPut(num, data) {
if (data === undefined || data === null) {
data = "value";
Expand Down

0 comments on commit ff9cb1b

Please sign in to comment.