forked from febe19/bazo-miner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtx_verification_test.go
60 lines (50 loc) · 2.22 KB
/
tx_verification_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package miner
import (
"math/rand"
"testing"
"time"
"github.com/julwil/bazo-miner/protocol"
)
func TestFundsTxVerification(t *testing.T) {
randVar := rand.New(rand.NewSource(time.Now().Unix()))
loopMax := int(randVar.Uint64() % 1000)
accAHash := protocol.SerializeHashContent(accA.Address)
accBHash := protocol.SerializeHashContent(accB.Address)
for i := 0; i < loopMax; i++ {
tx, _ := protocol.ConstrFundsTx(0x01, randVar.Uint64()%100000+1, randVar.Uint64()%10+1, uint32(i), accAHash, accBHash, PrivKeyAccA, PrivKeyMultiSig, nil)
if verifyFundsTx(tx) == false {
t.Errorf("Tx could not be verified: \n%v", tx)
}
}
}
func TestAccTx(t *testing.T) {
randVar := rand.New(rand.NewSource(time.Now().Unix()))
//Creating some root-signed new accounts
nullAccount := [64]byte{1}
loopMax := int(randVar.Uint64() % 1000)
for i := 0; i <= loopMax; i++ {
tx, _, _ := protocol.ConstrAccTx(0, randVar.Uint64()%100+1, nullAccount, PrivKeyRoot, nil, nil)
if verifyAccTx(tx) == false {
t.Errorf("AccTx could not be verified: %v\n", tx)
}
}
}
func TestConfigTx(t *testing.T) {
randVar := rand.New(rand.NewSource(time.Now().Unix()))
//creating some root-signed config txs
tx, err := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 1, 5000, randVar.Uint64(), 0, PrivKeyRoot)
tx2, err2 := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 2, 5000, randVar.Uint64(), 0, PrivKeyRoot)
tx3, err3 := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 3, 5000, randVar.Uint64(), 0, PrivKeyRoot)
tx4, err4 := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 4, 5000, randVar.Uint64(), 0, PrivKeyRoot)
tx5, err5 := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 5, 5000, randVar.Uint64(), 0, PrivKeyRoot)
//Add an invalid configTx, should not be accepted
txfail, err6 := protocol.ConstrConfigTx(uint8(randVar.Uint32()%256), 20, 5000, randVar.Uint64(), 0, PrivKeyRoot)
if (verifyConfigTx(tx) == false || err != nil) &&
(verifyConfigTx(tx2) == false || err2 != nil) &&
(verifyConfigTx(tx3) == false || err3 != nil) &&
(verifyConfigTx(tx4) == false || err4 != nil) &&
(verifyConfigTx(tx5) == false || err5 != nil) &&
(verifyConfigTx(txfail) == true || err6 != nil) {
t.Error("ConfigTx verification malfunctioning!")
}
}