-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,896 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package app | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
"github.com/ubclaunchpad/cumulus/blockchain" | ||
"github.com/ubclaunchpad/cumulus/msg" | ||
) | ||
|
||
func init() { | ||
log.SetLevel(log.InfoLevel) | ||
} | ||
|
||
func TestKillWorkers(t *testing.T) { | ||
intializeQueues() | ||
time.Sleep(20 * time.Millisecond) | ||
for i := 0; i < nWorkers; i++ { | ||
if workers[i] != nil { | ||
t.FailNow() | ||
} | ||
} | ||
initializeWorkers() | ||
time.Sleep(20 * time.Millisecond) | ||
for i := 0; i < nWorkers; i++ { | ||
if workers[i] == nil { | ||
t.FailNow() | ||
} | ||
} | ||
killWorkers() | ||
time.Sleep(20 * time.Millisecond) | ||
for i := 0; i < nWorkers; i++ { | ||
if workers[i] != nil { | ||
t.FailNow() | ||
} | ||
} | ||
} | ||
|
||
func TestInitializeNode(t *testing.T) { | ||
initializeNode() | ||
if tpool == nil { | ||
t.FailNow() | ||
} | ||
if BlockWorkQueue == nil { | ||
t.FailNow() | ||
} | ||
if TransactionWorkQueue == nil { | ||
t.FailNow() | ||
} | ||
killWorkers() | ||
} | ||
|
||
func TestPushHandlerNewBlock(t *testing.T) { | ||
intializeQueues() | ||
_, b := blockchain.NewValidTestChainAndBlock() | ||
push := msg.Push{ | ||
ResourceType: msg.ResourceBlock, | ||
Resource: b, | ||
} | ||
PushHandler(&push) | ||
select { | ||
case work, ok := <-BlockWorkQueue: | ||
if !ok { | ||
t.FailNow() | ||
} | ||
if work.Block != b { | ||
t.FailNow() | ||
} | ||
} | ||
// Add more here... | ||
} | ||
|
||
func TestPushHandlerNewTestTransaction(t *testing.T) { | ||
intializeQueues() | ||
txn := blockchain.NewTestTransaction() | ||
push := msg.Push{ | ||
ResourceType: msg.ResourceTransaction, | ||
Resource: txn, | ||
} | ||
PushHandler(&push) | ||
select { | ||
case work, ok := <-TransactionWorkQueue: | ||
if !ok { | ||
t.FailNow() | ||
} | ||
if work.Transaction != txn { | ||
t.FailNow() | ||
} | ||
} | ||
// Add more here... | ||
} | ||
|
||
func TestRequestHandlerNewBlock(t *testing.T) { | ||
intializeQueues() | ||
push := msg.Request{ResourceType: msg.ResourceBlock} | ||
RequestHandler(&push) | ||
select { | ||
case _, ok := <-BlockWorkQueue: | ||
if !ok { | ||
t.FailNow() | ||
} | ||
} | ||
// Add more here... | ||
} | ||
|
||
func TestRequestHandlerNewTestTransaction(t *testing.T) { | ||
intializeQueues() | ||
push := msg.Request{ResourceType: msg.ResourceTransaction} | ||
RequestHandler(&push) | ||
select { | ||
case _, ok := <-TransactionWorkQueue: | ||
if !ok { | ||
t.FailNow() | ||
} | ||
} | ||
// Add more here... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package app | ||
|
||
import "github.com/ubclaunchpad/cumulus/blockchain" | ||
|
||
const ( | ||
// BlockQueueSize is the size of the BlockQueue channel. | ||
BlockQueueSize = 100 | ||
// TransactionQueueSize is the size of the BlockQueue channel. | ||
TransactionQueueSize = 100 | ||
) | ||
|
||
// Responder is used to handle requests who require a response. | ||
type Responder interface { | ||
Send(ok bool) | ||
Lock() | ||
Unlock() | ||
} | ||
|
||
// BlockWorkQueue is a queue of blocks to process. | ||
var BlockWorkQueue = make(chan BlockWork, BlockQueueSize) | ||
|
||
// TransactionWorkQueue is a queue of transactions to process. | ||
var TransactionWorkQueue = make(chan TransactionWork, TransactionQueueSize) | ||
|
||
// TransactionWork holds a new transaction job, and a Responder for | ||
// sending results. | ||
type TransactionWork struct { | ||
*blockchain.Transaction | ||
Responder | ||
} | ||
|
||
// BlockWork holds a new block job, and a Responder for | ||
// sending results. | ||
type BlockWork struct { | ||
*blockchain.Block | ||
Responder | ||
} |
Oops, something went wrong.