-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigchaindb_test.go
63 lines (54 loc) · 1.69 KB
/
bigchaindb_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
61
62
63
//Date: 2017 Q4
//Email: [email protected]
//Author: Ali Mashatan
package GoBigChainDBDriver
import (
"testing"
"time"
)
func TestBigchain(t *testing.T) {
var headers map[string]string
headers = make(map[string]string)
headers["app_id"] = "b1d63ff3"
headers["app_key"] = "29913c6deb7ee2bd0709d6af3b382b44"
bcdb := NewBigChainDB("https://test.bigchaindb.com/api/v1/", &headers)
trans := NewCreateTransaction(JsonObj{"AssetKey": "AssetValue"}, JsonObj{"MetaDataKey": "MetaDataValue"})
pub, priv := GenerateKeypair()
alicePublic := []PublicKey{pub}
alicePrivate := []PrivateKey{priv}
trans.AddOwnerBefore(&alicePublic, &alicePrivate, nil)
trans.AddOwnerAfter(&alicePublic, 1)
trans.Sign()
tx, _ := trans.Generate(true, false)
txId, err := bcdb.NewTransaction(tx)
if err != nil {
println("Error :", err.Error())
} else {
println("Tx Id: ", string(txId))
}
var count int
for ok := true; ok; ok = (count < 60) {
status := bcdb.TransactionStatus(txId)
if status {
break
} else {
time.Sleep(1000 * time.Millisecond)
count++
}
}
bcdb.GetTransaction(txId)
pub, priv = GenerateKeypair()
bobPublic := []PublicKey{pub}
//bobPrivate := []PrivateKey{priv}
trans_trans := NewTransferTransaction(txId, JsonObj{"TransMetaDataKey": "TransMetaDataValue"})
trans_trans.AddOwnerBefore(&alicePublic, &alicePrivate, &JsonObj{"transaction_id": txId, "output_index": 0})
trans_trans.AddOwnerAfter(&bobPublic, 1)
trans_trans.Sign()
trans_tx, _ := trans_trans.Generate(true, false)
txId1, err := bcdb.NewTransaction(trans_tx)
if err != nil {
println("Error :", err.Error())
} else {
println("Tx Id: ", string(txId1))
}
}