Skip to content

Commit

Permalink
test expected fees
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Oct 26, 2018
1 parent 8c20dd9 commit 9f786f3
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions engine/factomd_test.go
Expand Up @@ -63,8 +63,7 @@ func SetupSim(GivenNodes string, UserAddedOptions map[string]string, height int,
"--stderrlog": "out.txt",
"--checkheads": "false",
"--controlpanelsetting": "readwrite",
//"--debuglog": "faulting|bad",
"--debuglog": ".",
"--debuglog": "faulting|bad",
"--logPort": "37000",
"--port": "37001",
"--controlpanelport": "37002",
Expand Down Expand Up @@ -1457,8 +1456,12 @@ func newTransaction(amt uint64, userSecretIn string, userPublicOut string, ecPri
}

func AssertEquals(t *testing.T, a interface{}, b interface{}) {
AssertEqualsMsg(t, a, b, "")
}

func AssertEqualsMsg(t *testing.T, a interface{}, b interface{}, msg string) {
if a != b {
t.Fatalf("%v != %v", a, b)
t.Fatalf("%v != %v %s", a, b, msg)
}
}

Expand Down Expand Up @@ -1509,7 +1512,6 @@ func TestTxnCreate(t *testing.T) {
}

func sendTxn(s *state.State, amt uint64, userSecretIn string, userPubOut string, ecPrice uint64) (*factoid.Transaction, error) {
//fmt.Printf("%v => %v\n", userPubOut, amt)
txn, _ := newTransaction(amt, userSecretIn, userPubOut, ecPrice)
msg := new(messages.FactoidTransaction)
msg.SetTransaction(txn)
Expand All @@ -1529,7 +1531,7 @@ func TestProcessedBlockFailure(t *testing.T) {

ranSimTest = true

state0 := SetupSim("LAF", map[string]string{"--debuglog": "fault|badmsg|network|process|dbsig", "--faulttimeout": "10", "--blktime": "5"}, 300, 0, 0, t)
state0 := SetupSim("LAF", map[string]string{"--debuglog": "fault|badmsg|network|process|dbsig", "--faulttimeout": "10", "--blktime": "5"}, 10, 0, 0, t)

var ecPrice uint64 = state0.GetFactoshisPerEC() //10000
var oneFct uint64 = factom.FactoidToFactoshi("1")
Expand Down Expand Up @@ -1592,34 +1594,41 @@ func TestProcessedBlockFailure(t *testing.T) {
// meaning both addresses show a balance > 0 at the same time
interval := time.Duration(100*time.Millisecond) // ms

fee := 12*ecPrice
pingCount := 0
mkTransactions := func(waitBlock int, waitMinute int) { // txnGenerator
WaitForBlock(state0, waitBlock)
WaitForMinute(state0, waitMinute)

fee := 12*ecPrice
bal := 10*oneFct

// fund the start address
sendTxn(state0, bal, bankSecret, depositAddresses[0], ecPrice)
time.Sleep(time.Second)
WaitMinutes(state0, 1)
waitForDeposit(0, bal)
pingCount++

println("->ping-pong<-")
delay := func() { time.Sleep(interval) }

for pingCount < 3 && state0.LLeaderHeight < uint32(maxBlocks-1) && bal > oneFct {
for pingCount < 2 && state0.LLeaderHeight < uint32(maxBlocks-1) && bal > oneFct {

bal = bal - fee
pingBal := bal
bal = bal - fee
pongBal := bal

ping := func() { sendTxn(state0, pingBal, depositSecrets[0], depositAddresses[1], ecPrice) }
pong := func() { sendTxn(state0, pongBal, depositSecrets[1], depositAddresses[0], ecPrice) }
ping := func() {
fmt.Printf("TXN %v %v => %v \n", pingBal, depositAddresses[0], depositAddresses[1])
sendTxn(state0, pingBal, depositSecrets[0], depositAddresses[1], ecPrice)
}
pong := func() {
fmt.Printf("TXN %v %v => %v \n", pongBal, depositAddresses[1], depositAddresses[0])
sendTxn(state0, pongBal, depositSecrets[1], depositAddresses[0], ecPrice)
}


if pingCount%2 == 0 {
if pingCount%2 == 1 {
println("txn in order")
// in order
ping()
Expand All @@ -1645,19 +1654,25 @@ func TestProcessedBlockFailure(t *testing.T) {

bal0 := getBalance(state0, depositAddresses[0])
bal1 := getBalance(state0, depositAddresses[1])
spent := int64(10*oneFct) - bal0+bal1

fmt.Printf(" %v => %v\n", depositAddresses[0], bal0)
fmt.Printf(" %v => %v\n", depositAddresses[1], bal1)
fmt.Printf(" burn => %v*fee =%v \n", spent/int64(fee), spent)

WaitMinutes(state0, 1)
//WaitBlocks(state0, 1)
//println("run forever")
//WaitForBlock(state0, 100000)

AssertEqualsMsg(t, spent, int64(fee)*4, "unexpected transaction fees")

if bal0 > bal1 {
AssertEquals(t, bal1, int64(0))
} else {
AssertEquals(t, bal0, int64(0))
}

// TODO: try to read journal or other source of txn data
// test to see which txn started the problem

WaitForAllNodes(state0)
shutDownEverything(t)
}
Expand Down

0 comments on commit 9f786f3

Please sign in to comment.