"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"
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)
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"
}
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)
InMainChain(bc.Hash) bool
ProcessBlock(*types.Block) (bool, error)
ValidateTx(*types.Tx) (bool, error)
- GetAuthoritys(string) string
}
"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"
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()
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()
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 {
c.position = position
}
-func (c *Chain) GetAuthoritys(key string) string {
- return c.Authoritys[key]
-}
-
func (c *Chain) SetConsensusEngine(engine engine.Engine) {
c.engine = engine
}
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 {
"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"
// 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)
"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"
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
}
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"
)
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)
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)
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)
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"
)
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)
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)
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
}