From: mars Date: Tue, 8 Jan 2019 01:51:06 +0000 (+0800) Subject: fix ci X-Git-Tag: v1.0.5~221^2~2^2 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=a7c5e4f0b8dab4ffe44a5e20fe5e1e30db14026c fix ci --- diff --git a/account/accounts_test.go b/account/accounts_test.go index 413283ad..f94c51ca 100644 --- a/account/accounts_test.go +++ b/account/accounts_test.go @@ -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) diff --git a/asset/asset_test.go b/asset/asset_test.go index cdc1d66c..f0127eea 100644 --- a/asset/asset_test.go +++ b/asset/asset_test.go @@ -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) diff --git a/chain/chain.go b/chain/chain.go index 7279cf69..5fe5b160 100644 --- a/chain/chain.go +++ b/chain/chain.go @@ -18,5 +18,4 @@ type Chain interface { InMainChain(bc.Hash) bool ProcessBlock(*types.Block) (bool, error) ValidateTx(*types.Tx) (bool, error) - GetAuthoritys(string) string } diff --git a/database/leveldb/store_test.go b/database/leveldb/store_test.go index 9d2bc766..ddad037a 100644 --- a/database/leveldb/store_test.go +++ b/database/leveldb/store_test.go @@ -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() diff --git a/protocol/block_test.go b/protocol/block_test.go index eae3d8f1..f60d4399 100644 --- a/protocol/block_test.go +++ b/protocol/block_test.go @@ -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 { diff --git a/protocol/protocol.go b/protocol/protocol.go index abd6ddbd..ff61e185 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -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 } diff --git a/protocol/txpool_test.go b/protocol/txpool_test.go index 808a3f60..0bca2d71 100644 --- a/protocol/txpool_test.go +++ b/protocol/txpool_test.go @@ -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 { diff --git a/test/util.go b/test/util.go index dd1c17ac..b534a42a 100644 --- a/test/util.go +++ b/test/util.go @@ -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) diff --git a/test/wallet_test_util.go b/test/wallet_test_util.go index f2825a40..261c087a 100644 --- a/test/wallet_test_util.go +++ b/test/wallet_test_util.go @@ -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 } diff --git a/wallet/unconfirmed_test.go b/wallet/unconfirmed_test.go index 25dae787..047e4120 100644 --- a/wallet/unconfirmed_test.go +++ b/wallet/unconfirmed_test.go @@ -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) diff --git a/wallet/utxo.go b/wallet/utxo.go index a2ffb92e..8060965c 100644 --- a/wallet/utxo.go +++ b/wallet/utxo.go @@ -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) diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index a08a4c56..519a6b7a 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -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 }