Skip to content
Snippets Groups Projects
Commit e9a62021 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

copy @silasdavis corrections from state into manager/eris-mint/state

parent 6466cb62
No related branches found
No related tags found
No related merge requests found
......@@ -4,11 +4,17 @@ import (
"bytes"
"encoding/hex"
"fmt"
"sort"
"testing"
"time"
acm "github.com/eris-ltd/eris-db/manager/eris-mint/account"
ptypes "github.com/eris-ltd/eris-db/permission/types"
. "github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
. "github.com/tendermint/go-common"
tdb "github.com/tendermint/go-db"
"github.com/tendermint/tendermint/types"
)
var chain_id = "lone_ranger"
......@@ -41,7 +47,7 @@ var g1 = fmt.Sprintf(`
"validators": [
{
"amount": 100000000,
"pub_key": "F6C79CF0CB9D66B677988BCB9B8EADD9A091CD465A60542A8AB85476256DBA92",
"pub_key": [1,"F6C79CF0CB9D66B677988BCB9B8EADD9A091CD465A60542A8AB85476256DBA92"],
"unbond_to": [
{
"address": "964B1493BBE3312278B7DEB94C39149F7899A345",
......@@ -85,3 +91,68 @@ func TestGenesisMakeState(t *testing.T) {
t.Fatalf("Incorrect permission for send. Got %v, expected %v\n", v, send1 > 0)
}
}
//-------------------------------------------------------
func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*acm.PrivAccount, []*types.PrivValidator) {
db := tdb.NewMemDB()
genDoc, privAccounts, privValidators := RandGenesisDoc(numAccounts, randBalance, minBalance, numValidators, randBonded, minBonded)
s0 := MakeGenesisState(db, genDoc)
s0.Save()
return s0, privAccounts, privValidators
}
func RandAccount(randBalance bool, minBalance int64) (*acm.Account, *acm.PrivAccount) {
privAccount := acm.GenPrivAccount()
perms := ptypes.DefaultAccountPermissions
acc := &acm.Account{
Address: privAccount.PubKey.Address(),
PubKey: privAccount.PubKey,
Sequence: RandInt(),
Balance: minBalance,
Permissions: perms,
}
if randBalance {
acc.Balance += int64(RandUint32())
}
return acc, privAccount
}
func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*GenesisDoc, []*acm.PrivAccount, []*types.PrivValidator) {
accounts := make([]GenesisAccount, numAccounts)
privAccounts := make([]*acm.PrivAccount, numAccounts)
defaultPerms := ptypes.DefaultAccountPermissions
for i := 0; i < numAccounts; i++ {
account, privAccount := RandAccount(randBalance, minBalance)
accounts[i] = GenesisAccount{
Address: account.Address,
Amount: account.Balance,
Permissions: &defaultPerms, // This will get copied into each state.Account.
}
privAccounts[i] = privAccount
}
validators := make([]GenesisValidator, numValidators)
privValidators := make([]*types.PrivValidator, numValidators)
for i := 0; i < numValidators; i++ {
valInfo, privVal := types.RandValidator(randBonded, minBonded)
validators[i] = GenesisValidator{
PubKey: valInfo.PubKey,
Amount: valInfo.VotingPower,
UnbondTo: []BasicAccount{
{
Address: valInfo.PubKey.Address(),
Amount: valInfo.VotingPower,
},
},
}
privValidators[i] = privVal
}
sort.Sort(types.PrivValidatorsByAddress(privValidators))
return &GenesisDoc{
GenesisTime: time.Now(),
ChainID: "tendermint_test",
Accounts: accounts,
Validators: validators,
}, privAccounts, privValidators
}
......@@ -9,6 +9,7 @@ import (
"time"
acm "github.com/eris-ltd/eris-db/manager/eris-mint/account"
"github.com/eris-ltd/eris-db/manager/eris-mint/evm"
ptypes "github.com/eris-ltd/eris-db/permission/types"
. "github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
"github.com/eris-ltd/eris-db/txs"
......@@ -142,7 +143,7 @@ func newBaseGenDoc(globalPerm, accountPerm ptypes.AccountPermissions) GenesisDoc
}
func TestSendFails(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[1].Permissions.Base.Set(ptypes.Send, true)
genDoc.Accounts[2].Permissions.Base.Set(ptypes.Call, true)
......@@ -210,7 +211,7 @@ func TestSendFails(t *testing.T) {
}
func TestName(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Send, true)
genDoc.Accounts[1].Permissions.Base.Set(ptypes.Name, true)
......@@ -244,7 +245,7 @@ func TestName(t *testing.T) {
}
func TestCallFails(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[1].Permissions.Base.Set(ptypes.Send, true)
genDoc.Accounts[2].Permissions.Base.Set(ptypes.Call, true)
......@@ -314,7 +315,7 @@ func TestCallFails(t *testing.T) {
}
func TestSendPermission(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Send, true) // give the 0 account permission
st := MakeGenesisState(stateDB, &genDoc)
......@@ -350,7 +351,7 @@ func TestSendPermission(t *testing.T) {
}
func TestCallPermission(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Call, true) // give the 0 account permission
st := MakeGenesisState(stateDB, &genDoc)
......@@ -472,7 +473,7 @@ func TestCallPermission(t *testing.T) {
}
func TestCreatePermission(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.CreateContract, true) // give the 0 account permission
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Call, true) // give the 0 account permission
......@@ -590,7 +591,7 @@ func TestCreatePermission(t *testing.T) {
/* TODO
func TestBondPermission(t *testing.T) {
stateDB := dbm.GetDB("state",dbBackend,dbDir)
stateDB := dbm.NewDB("state",dbBackend,dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
st := MakeGenesisState(stateDB, &genDoc)
blockCache := NewBlockCache(st)
......@@ -714,7 +715,7 @@ func TestBondPermission(t *testing.T) {
*/
func TestCreateAccountPermission(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Send, true) // give the 0 account permission
genDoc.Accounts[1].Permissions.Base.Set(ptypes.Send, true) // give the 0 account permission
......@@ -857,7 +858,7 @@ func TestCreateAccountPermission(t *testing.T) {
var DougAddress = append([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, []byte("THISISDOUG")...)
func TestSNativeCALL(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Call, true) // give the 0 account permission
genDoc.Accounts[3].Permissions.Base.Set(ptypes.Bond, true) // some arbitrary permission to play with
......@@ -991,7 +992,7 @@ func TestSNativeCALL(t *testing.T) {
}
func TestSNativeTx(t *testing.T) {
stateDB := dbm.GetDB("state", dbBackend, dbDir)
stateDB := dbm.NewDB("state", dbBackend, dbDir)
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
genDoc.Accounts[0].Permissions.Base.Set(ptypes.Call, true) // give the 0 account permission
genDoc.Accounts[3].Permissions.Base.Set(ptypes.Bond, true) // some arbitrary permission to play with
......
......@@ -4,12 +4,11 @@ import (
"bytes"
"testing"
"github.com/tendermint/go-wire"
)
func TestStateToFromVMAccount(t *testing.T) {
acmAcc1, _ := stypes.RandAccount(true, 456)
acmAcc1, _ := RandAccount(true, 456)
vmAcc := toVMAccount(acmAcc1)
acmAcc2 := toStateAccount(vmAcc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment