OSDN Git Service

fix ci
authormars <mars@bytom.io>
Tue, 8 Jan 2019 01:51:06 +0000 (09:51 +0800)
committermars <mars@bytom.io>
Tue, 8 Jan 2019 04:26:54 +0000 (12:26 +0800)
12 files changed:
account/accounts_test.go
asset/asset_test.go
chain/chain.go
database/leveldb/store_test.go
protocol/block_test.go
protocol/protocol.go
protocol/txpool_test.go
test/util.go
test/wallet_test_util.go
wallet/unconfirmed_test.go
wallet/utxo.go
wallet/wallet_test.go

index 413283a..f94c51c 100644 (file)
@@ -11,6 +11,8 @@ import (
 
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
+       "github.com/vapor/common"
+       "github.com/vapor/config"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database/leveldb"
@@ -207,8 +209,17 @@ func TestGetAccountIndexKey(t *testing.T) {
 
 func mockAccountManager(t *testing.T) *Manager {
 
-       consensus.ActiveNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
-
+       config.CommonConfig = config.DefaultConfig()
+       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
        dirPath, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatal(err)
index cdc1d66..f0127ee 100644 (file)
@@ -11,6 +11,8 @@ import (
 
        dbm "github.com/tendermint/tmlibs/db"
 
+       "github.com/vapor/common"
+       "github.com/vapor/config"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database/leveldb"
@@ -161,7 +163,17 @@ func mockChain(testDB dbm.DB) (*protocol.Chain, error) {
 }
 
 func mockNewRegistry(t *testing.T) *Registry {
-       consensus.ActiveNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig = config.DefaultConfig()
+       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
        dirPath, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatal(err)
index 7279cf6..5fe5b16 100644 (file)
@@ -18,5 +18,4 @@ type Chain interface {
        InMainChain(bc.Hash) bool
        ProcessBlock(*types.Block) (bool, error)
        ValidateTx(*types.Tx) (bool, error)
-       GetAuthoritys(string) string
 }
index 9d2bc76..ddad037 100644 (file)
@@ -4,7 +4,9 @@ import (
        "os"
        "testing"
 
+       "github.com/vapor/common"
        "github.com/vapor/config"
+       "github.com/vapor/consensus"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
 
@@ -15,7 +17,16 @@ func TestLoadBlockIndex(t *testing.T) {
        defer os.RemoveAll("temp")
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        store := NewStore(testDB)
-
+       config.CommonConfig = config.DefaultConfig()
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
        block := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()
 
@@ -70,6 +81,16 @@ func TestLoadBlockIndexBestHeight(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        store := NewStore(testDB)
        var savedBlocks []types.Block
+       config.CommonConfig = config.DefaultConfig()
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
 
        for _, c := range cases {
                block := config.GenesisBlock()
index eae3d8f..f60d439 100644 (file)
@@ -3,13 +3,25 @@ package protocol
 import (
        "testing"
 
+       "github.com/vapor/common"
        "github.com/vapor/config"
+       "github.com/vapor/consensus"
        "github.com/vapor/protocol/state"
        "github.com/vapor/testutil"
 )
 
 func TestCalcReorganizeNodes(t *testing.T) {
        c := &Chain{index: state.NewBlockIndex()}
+       config.CommonConfig = config.DefaultConfig()
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
        header := config.GenesisBlock().BlockHeader
        initNode, err := state.NewBlockNode(&header, nil)
        if err != nil {
index abd6ddb..ff61e18 100644 (file)
@@ -67,10 +67,6 @@ func (c *Chain) SetPosition(position uint64) {
        c.position = position
 }
 
-func (c *Chain) GetAuthoritys(key string) string {
-       return c.Authoritys[key]
-}
-
 func (c *Chain) SetConsensusEngine(engine engine.Engine) {
        c.engine = engine
 }
index 808a3f6..0bca2d7 100644 (file)
@@ -78,6 +78,8 @@ func (s *mockStore) SaveBlock(*types.Block, *bc.TransactionStatus) error
 func (s *mockStore) SaveChainStatus(*state.BlockNode, *state.UtxoViewpoint) error { return nil }
 func (s *mockStore) IsWithdrawSpent(hash *bc.Hash) bool                           { return true }
 func (s *mockStore) SetWithdrawSpent(hash *bc.Hash)                               {}
+func (s *mockStore) Set(hash *bc.Hash, data []byte) error                         { return nil }
+func (s *mockStore) Get(hash *bc.Hash) ([]byte, error)                            { return nil, nil }
 
 func TestAddOrphan(t *testing.T) {
        cases := []struct {
index dd1c17a..b534a42 100644 (file)
@@ -9,6 +9,8 @@ import (
        "github.com/vapor/account"
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/txbuilder"
+       "github.com/vapor/common"
+       "github.com/vapor/config"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database/leveldb"
@@ -25,6 +27,18 @@ const (
 
 // MockChain mock chain with genesis block
 func MockChain(testDB dbm.DB) (*protocol.Chain, *leveldb.Store, *protocol.TxPool, error) {
+       config.CommonConfig = config.DefaultConfig()
+       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       return nil, nil, nil, err
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
+
        store := leveldb.NewStore(testDB)
        txPool := protocol.NewTxPool(store)
        chain, err := protocol.NewChain(store, txPool)
index f2825a4..261c087 100644 (file)
@@ -13,6 +13,9 @@ import (
        "github.com/vapor/asset"
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
+       "github.com/vapor/common"
+       "github.com/vapor/config"
+       "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc/types"
@@ -256,10 +259,15 @@ func (cfg *walletTestConfig) Run() error {
        if err != nil {
                return err
        }
+       config.CommonConfig.Consensus.Dpos.Coinbase = "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep"
+       address, err := common.DecodeAddress(config.CommonConfig.Consensus.Dpos.Coinbase, &consensus.SoloNetParams)
+       if err != nil {
+               return err
+       }
        walletDB := dbm.NewDB("wallet", "leveldb", path.Join(dirPath, "wallet_db"))
        accountManager := account.NewManager(walletDB, chain)
        assets := asset.NewRegistry(walletDB, chain)
-       wallet, err := w.NewWallet(walletDB, accountManager, assets, hsm, chain)
+       wallet, err := w.NewWallet(walletDB, accountManager, assets, hsm, chain, address)
        if err != nil {
                return err
        }
index 25dae78..047e412 100644 (file)
@@ -7,6 +7,8 @@ import (
 
        dbm "github.com/tendermint/tmlibs/db"
        "github.com/vapor/blockchain/signers"
+       "github.com/vapor/common"
+       "github.com/vapor/config"
 
        "github.com/vapor/account"
        "github.com/vapor/asset"
@@ -19,6 +21,22 @@ import (
 )
 
 func TestWalletUnconfirmedTxs(t *testing.T) {
+       config.CommonConfig = config.DefaultConfig()
+       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
+       config.CommonConfig.Consensus.Dpos.Coinbase = "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep"
+       address, err := common.DecodeAddress(config.CommonConfig.Consensus.Dpos.Coinbase, &consensus.SoloNetParams)
+       if err != nil {
+               t.Fatal(err)
+       }
        dirPath, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatal(err)
@@ -57,7 +75,7 @@ func TestWalletUnconfirmedTxs(t *testing.T) {
                t.Fatal(err)
        }
 
-       w := mockWallet(testDB, accountManager, reg, nil)
+       w := mockWallet(testDB, accountManager, reg, nil, address)
        utxos := []*account.UTXO{}
        btmUtxo := mockUTXO(controlProg, consensus.BTMAssetID)
        utxos = append(utxos, btmUtxo)
index a2ffb92..8060965 100644 (file)
@@ -127,8 +127,12 @@ func (w *Wallet) detachUtxos(batch db.Batch, b *types.Block, txStatus *bc.Transa
 
 func (w *Wallet) filterAccountUtxo(utxos []*account.UTXO) []*account.UTXO {
        outsByScript := make(map[string][]*account.UTXO, len(utxos))
-       redeemContract := w.dposAddress.ScriptAddress()
-       program, _ := vmutil.P2WPKHProgram(redeemContract)
+       var program []byte
+       if w.dposAddress != nil {
+               redeemContract := w.dposAddress.ScriptAddress()
+               program, _ = vmutil.P2WPKHProgram(redeemContract)
+       }
+
        isDposAddress := false
        for _, utxo := range utxos {
                scriptStr := string(utxo.ControlProgram)
index a08a4c5..519a6b7 100644 (file)
@@ -8,6 +8,8 @@ import (
 
        dbm "github.com/tendermint/tmlibs/db"
        "github.com/vapor/blockchain/signers"
+       "github.com/vapor/common"
+       "github.com/vapor/config"
 
        "github.com/vapor/account"
        "github.com/vapor/asset"
@@ -22,6 +24,23 @@ import (
 )
 
 func TestWalletUpdate(t *testing.T) {
+       config.CommonConfig = config.DefaultConfig()
+       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
+       config.CommonConfig.Consensus.Dpos.SelfVoteSigners = append(config.CommonConfig.Consensus.Dpos.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
+       config.CommonConfig.Consensus.Dpos.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
+       for _, v := range config.CommonConfig.Consensus.Dpos.SelfVoteSigners {
+               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
+               if err != nil {
+                       t.Fatal(err)
+               }
+               config.CommonConfig.Consensus.Dpos.Signers = append(config.CommonConfig.Consensus.Dpos.Signers, address)
+       }
+       config.CommonConfig.Consensus.Dpos.Coinbase = "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep"
+       address, err := common.DecodeAddress(config.CommonConfig.Consensus.Dpos.Coinbase, &consensus.SoloNetParams)
+       if err != nil {
+               t.Fatal(err)
+       }
+
        dirPath, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatal(err)
@@ -84,8 +103,7 @@ func TestWalletUpdate(t *testing.T) {
        txStatus := bc.NewTransactionStatus()
        txStatus.SetStatus(0, false)
        store.SaveBlock(block, txStatus)
-
-       w := mockWallet(testDB, accountManager, reg, chain)
+       w := mockWallet(testDB, accountManager, reg, chain, address)
        err = w.AttachBlock(block)
        if err != nil {
                t.Fatal(err)
@@ -137,13 +155,14 @@ func mockTxData(utxos []*account.UTXO, testAccount *account.Account) (*txbuilder
        return tplBuilder.Build()
 }
 
-func mockWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, chain *protocol.Chain) *Wallet {
+func mockWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, chain *protocol.Chain, address common.Address) *Wallet {
        wallet := &Wallet{
                DB:          walletDB,
                AccountMgr:  account,
                AssetReg:    asset,
                chain:       chain,
                RecoveryMgr: newRecoveryManager(walletDB, account),
+               dposAddress: address,
        }
        return wallet
 }