forked from rooch-network/rooch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitcoin.feature
100 lines (73 loc) · 3.7 KB
/
bitcoin.feature
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Feature: Rooch Bitcoin tests
@serial
Scenario: rooch bitcoin test
# prepare servers
Given a bitcoind server for rooch_bitcoin_test
Given a server for rooch_bitcoin_test
Then cmd: "account list --json"
# mint utxos
Then cmd bitcoin-cli: "generatetoaddress 101 {{$.account[-1].default.bitcoin_address}}"
Then sleep: "10" # wait rooch sync and index
# query utxos
Then cmd: "object -t 0x4::utxo::UTXO -o {{$.account[-1].default.bitcoin_address}}"
Then assert: "{{$.object[-1].data[0].owner}} == {{$.account[-1].default.address}}"
# release servers
Then stop the server
Then stop the bitcoind server
@serial
Scenario: rooch bitcoin reorg test
# prepare servers
Given a bitcoind server for bitcoin_reorg_test
Given a server for bitcoin_reorg_test
# Wait genesis block synced
Then sleep: "10" # wait rooch sync and index
# Update the reorg pending block count
Then cmd: "move run --function 0x4::pending_block::update_reorg_block_count_for_local --args u64:1 --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "account list --json"
# mint utxos
Then cmd bitcoin-cli: "generatetoaddress 2 {{$.account[-1].default.bitcoin_address}}"
Then sleep: "10" # wait rooch sync and index
Then cmd bitcoin-cli: "getbestblockhash"
# invalid the latest
Then cmd bitcoin-cli: "invalidateblock {{$.getbestblockhash[-1]}}"
# generate a new block
Then cmd bitcoin-cli: "generatetoaddress 2 {{$.account[-1].default.bitcoin_address}}"
Then sleep: "10" # wait rooch sync and index
Then cmd: "event get-events-by-event-handle -t 0x4::pending_block::ReorgEvent --descending-order true"
Then assert: "{{$.event[-1].data[0].decoded_event_data.value.success}} == true"
# release servers
Then stop the server
Then stop the bitcoind server
@serial
Scenario: rooch bitcoin api test
Then cmd: "init --skip-password"
Then cmd: "env switch --alias local"
# prepare servers
Given a bitcoind server for rooch_bitcoin_api_test
Given a server for rooch_bitcoin_api_test
# Create and load a wallet
Then cmd bitcoin-cli: "createwallet \"test_wallet\""
Then cmd bitcoin-cli: "loadwallet \"test_wallet\""
# Prepare funds
Then cmd bitcoin-cli: "getnewaddress"
# mint utxos
Then cmd bitcoin-cli: "generatetoaddress 101 {{$.getnewaddress[-1]}}"
Then sleep: "10" # wait rooch sync and index
# Get UTXO for transaction input
Then cmd bitcoin-cli: "listunspent 1 9999999 [\"{{$.getnewaddress[-1]}}\"] true"
# Create a Bitcoin transaction
Then cmd bitcoin-cli: "createrawtransaction [{\"txid\":\"{{$.listunspent[-1][0].txid}}\",\"vout\":{{$.listunspent[-1][0].vout}}}] {\"{{$.getnewaddress[-1]}}\":49.999}"
Then cmd bitcoin-cli: "signrawtransactionwithwallet {{$.createrawtransaction[-1]}}"
# Broadcast transaction using Rooch RPC
Then cmd: "rpc request --method btc_broadcastTX --params '["{{$.signrawtransactionwithwallet[-1].hex}}", 0.1, 0.1]' --json"
# Verify transaction broadcast
Then cmd bitcoin-cli: "getrawmempool"
Then assert: "{{$.getrawmempool[-1][0]}} == {{$.rpc[-1]}}"
Then cmd bitcoin-cli: "generatetoaddress 1 {{$.getnewaddress[-1]}}"
Then sleep: "10" # wait for the transaction to be confirmed
Then cmd bitcoin-cli: "gettransaction {{$.rpc[-1]}}"
Then assert: "{{$.gettransaction[-1].confirmations}} == 1"
# release servers
Then stop the server
Then stop the bitcoind server