Commit 1c7a5010 authored by David Vorick's avatar David Vorick

change e to c for testing files

parent bc483606
......@@ -6,10 +6,13 @@ fmt:
install: fmt
go install ./...
test: install
clean:
rm -rf host release whitepaper.aux whitepaper.log whitepaper.pdf siacore/test.wallet
test: clean install
go test -short ./...
test-long: install
test-long: clean install
go test -v -race -tags=debug ./...
# run twice to ensure references are updated properly
......@@ -23,9 +26,6 @@ dependencies:
go get -u github.com/mitchellh/go-homedir
go get -u github.com/spf13/cobra
clean:
rm -rf host release whitepaper.aux whitepaper.log whitepaper.pdf siacore/test.wallet
# Cross Compile - makes binaries for windows, linux, and mac, 32 and 64 bit.
xc:
go get -u github.com/laher/goxc
......
......@@ -7,60 +7,60 @@ import (
)
// testEmptyBlock creates an emtpy block and submits it to the state, checking that a utxo is created for the miner subisdy.
func testEmptyBlock(t *testing.T, e *Core) {
func testEmptyBlock(t *testing.T, c *Core) {
// Check that the block will actually be empty.
if len(e.state.TransactionPoolDump()) != 0 {
if len(c.state.TransactionPoolDump()) != 0 {
t.Error("TransactionPoolDump is not of len 0")
return
}
// Create and submit the block.
height := e.Height()
utxoSize := len(e.state.SortedUtxoSet())
mineSingleBlock(t, e)
if height+1 != e.Height() {
t.Errorf("height should have increased by one, went from %v to %v.", height, e.Height())
height := c.Height()
utxoSize := len(c.state.SortedUtxoSet())
mineSingleBlock(t, c)
if height+1 != c.Height() {
t.Errorf("height should have increased by one, went from %v to %v.", height, c.Height())
}
if utxoSize+1 != len(e.state.SortedUtxoSet()) {
t.Errorf("utxo set should have increased by one, went from %v to %v.", utxoSize, len(e.state.SortedUtxoSet()))
if utxoSize+1 != len(c.state.SortedUtxoSet()) {
t.Errorf("utxo set should have increased by one, went from %v to %v.", utxoSize, len(c.state.SortedUtxoSet()))
}
}
// testTransactionBlock creates a transaction and checks that it makes it into
// the utxo set.
func testTransactionBlock(t *testing.T, e *Core) {
func testTransactionBlock(t *testing.T, c *Core) {
// As a prereq the balance of the wallet needs to be non-zero.
// Alternatively we could probably mine a block.
if e.wallet.Balance(false) == 0 {
t.Error("e.wallet is empty.")
if c.wallet.Balance(false) == 0 {
t.Error("c.wallet is empty.")
return
}
// Send all coins to the `1` address.
dest := consensus.CoinAddress{1}
txn, err := e.SpendCoins(e.wallet.Balance(false)-10, dest)
txn, err := c.SpendCoins(c.wallet.Balance(false)-10, dest)
if err != nil {
t.Error(err)
return
}
err = e.processTransaction(txn)
err = c.processTransaction(txn)
if err != nil {
t.Error(err)
}
// Check that the transaction made it into the transaction pool.
if len(e.state.TransactionPoolDump()) != 1 {
t.Error("transaction pool not len 1", len(e.state.TransactionPoolDump()))
if len(c.state.TransactionPoolDump()) != 1 {
t.Error("transaction pool not len 1", len(c.state.TransactionPoolDump()))
}
// Check that the balance of e.wallet.Balance(false) has dropped to 0.
if e.wallet.Balance(false) != 0 {
t.Error("wallet.Balance(false) should be 0, but instead is", e.wallet.Balance(false))
// Check that the balance of c.wallet.Balance(false) has dropped to 0.
if c.wallet.Balance(false) != 0 {
t.Error("wallet.Balance(false) should be 0, but instead is", c.wallet.Balance(false))
}
// Mine the block and see if the outputs moved.
mineSingleBlock(t, e)
sortedSet := e.state.SortedUtxoSet()
mineSingleBlock(t, c)
sortedSet := c.state.SortedUtxoSet()
if len(sortedSet) != 3 {
t.Error(sortedSet)
t.Fatal("expecting sortedSet to be len 3, got", len(sortedSet))
......@@ -83,10 +83,10 @@ func testTransactionBlock(t *testing.T, e *Core) {
// Check that the full wallet balance is reporting to only have the miner
// subsidy.
minerSubsidy := consensus.CalculateCoinbase(e.Height())
minerSubsidy := consensus.CalculateCoinbase(c.Height())
minerSubsidy += 10 // TODO: Wallet figures out miner fee.
if e.wallet.Balance(true) != minerSubsidy {
t.Errorf("full balance not reporting correctly, should be %v but instead is %v", minerSubsidy, e.wallet.Balance(true))
if c.wallet.Balance(true) != minerSubsidy {
t.Errorf("full balance not reporting correctly, should be %v but instead is %v", minerSubsidy, c.wallet.Balance(true))
return
}
}
......@@ -52,9 +52,9 @@ func establishTestingEnvironment(t *testing.T) (e *Core) {
// I'm not sure how to test asynchronous code, so at this point I don't try, I
// only test the synchronous parts.
func TestEverything(t *testing.T) {
e := establishTestingEnvironment(t)
testEmptyBlock(t, e)
testTransactionBlock(t, e)
testSendToSelf(t, e)
testWalletInfo(t, e)
c := establishTestingEnvironment(t)
testEmptyBlock(t, c)
testTransactionBlock(t, c)
testSendToSelf(t, c)
testWalletInfo(t, c)
}
......@@ -9,42 +9,42 @@ import (
// testSendToSelf does a send from the wallet to itself, and checks that all of
// the balance reporting at each step makes sense, and then checks that all of
// the coins are still sendable.
func testSendToSelf(t *testing.T, e *Core) {
if e.wallet.Balance(false) == 0 {
t.Error("e.wallet is empty.")
func testSendToSelf(t *testing.T, c *Core) {
if c.wallet.Balance(false) == 0 {
t.Error("c.wallet is empty.")
return
}
originalBalance := e.wallet.Balance(false)
originalBalance := c.wallet.Balance(false)
// Get a new coin address from the wallet and send the coins to yourself.
dest, err := e.wallet.CoinAddress()
dest, err := c.wallet.CoinAddress()
if err != nil {
t.Error(err)
return
}
txn, err := e.SpendCoins(e.wallet.Balance(false)-10, dest)
txn, err := c.SpendCoins(c.wallet.Balance(false)-10, dest)
if err != nil {
t.Error(err)
return
}
// Process the transaction and check the balance, which should now be 0.
err = e.processTransaction(txn)
err = c.processTransaction(txn)
if err != nil {
t.Error(err)
}
if e.wallet.Balance(false) != 0 {
t.Error("Expecting a balance of 0, got", e.wallet.Balance(false))
if c.wallet.Balance(false) != 0 {
t.Error("Expecting a balance of 0, got", c.wallet.Balance(false))
}
// Mine the block and check the balance, which should now be
// originalBalance + Coinbase.
mineSingleBlock(t, e)
if e.wallet.Balance(false) != originalBalance+consensus.CalculateCoinbase(e.Height()) {
t.Errorf("Expecting a balance of %v, got %v", originalBalance+consensus.CalculateCoinbase(e.Height()), e.wallet.Balance(false))
mineSingleBlock(t, c)
if c.wallet.Balance(false) != originalBalance+consensus.CalculateCoinbase(c.Height()) {
t.Errorf("Expecting a balance of %v, got %v", originalBalance+consensus.CalculateCoinbase(c.Height()), c.wallet.Balance(false))
}
if e.wallet.Balance(false) != e.wallet.Balance(true) {
t.Errorf("Expecting balance and full balance to be equal, but instead they are false: %v, full: %v", e.wallet.Balance(false), e.wallet.Balance(true))
if c.wallet.Balance(false) != c.wallet.Balance(true) {
t.Errorf("Expecting balance and full balance to be equal, but instead they are false: %v, full: %v", c.wallet.Balance(false), c.wallet.Balance(true))
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment