decred / dcrd

Decred daemon in Go (golang).
https://decred.org
ISC License
740 stars 291 forks source link

Implement a system testing environment that can be utilized for high-level black-box testing #1506

Closed ggoranov closed 5 years ago

ggoranov commented 5 years ago

Problem:

There is not a testing mechanism where a developer can automate the testing of issues like https://github.com/decred/dcrwallet/issues/1297

Proposal:

Advantages:

Example:

Issue: dcrwallet/issues/1297

Pseudo code:


////////////////////////////////////////////////////
// Initialization 
simnet := NewSimnet( LINUX /*platform*/ )

wallet := createMiningWallet(simnet)
wallet.debugLevel  = "trace"

node := createSimnetNode(simnet, num)
    node.config.spv = false
    node.config.miningAddr = wallet.Addr

//NB By default any rpc credentials are handled by the environment

// Create additional 2 nodes
for num := 0: num < 2; num++ {
        node := createSimnetNode(simnet, num)
    node.config.spv = false
    node.config.debugLevel = "trace"
    }

// this will ..
//  create docker containers,
//  build dcrd/dcrdwallet from master or local branch
//  set configurations per node
//  Run all dcrd and dcrwallet instances

simnet.start();

////////////////////////////////////////////////////
// Definition

// Mine 1 block only (the  premine block )
simnet.mine( 1 /*node_id*/,  1 /*blocks count*/ )

// Check if no coinbase transaction was noticed by the wallet
CHECK_IS_TRUE( simnet.miningWallet.Balance() == 0 )

// Mine 1 blocks only 
simnet.mine( 1 /*node_id*/,  1 /*blocks count*/ )

// Check if second coinbase transaction was noticed by the wallet
CHECK_IS_TRUE( simnet.miningWallet.Balance() == COINBASE_REWARD )

////////////////////////////////////////////////////
//  Clean-up
simnet.stop();
ggoranov commented 5 years ago

Seems that similar idea was already implemented in https://github.com/btcsuite/btcsim. So not sure if it makes sense in the context of Decred. @davecgh Your input here would be helpful.

davecgh commented 5 years ago

I suggest taking a look at rpctest which already effectively provides the capability. It's also worth noting that @JFixby has been working to split it up into more reusable modules and clean it up a bit.

davecgh commented 5 years ago

For example, see the RPC server test file setup.

ggoranov commented 5 years ago

@davecgh Seems you've already made progress on that idea.

JFixby commented 5 years ago

I confirm I have something in progress in this direction.