Skip to content

Commit d76c4c0

Browse files
1mafiatjaf
authored andcommitted
use trustedcoin in integration test, and fix estimatefees and bitcoin-datadir errors
1 parent 6df4ea9 commit d76c4c0

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__pycache__/
22
dist/
33
trustedcoin
4-
venv/
4+
venv/

estimatefees.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@ type FeeRate struct {
1818
FeeRate int `json:"feerate"`
1919
}
2020

21-
func getFeeRates() (*EstimatedFees, error) {
21+
func getFeeRates(network string) (*EstimatedFees, error) {
22+
if network == "regtest" {
23+
return &EstimatedFees{
24+
FeeRateFloor: 1000,
25+
FeeRates: []FeeRate{
26+
{Blocks: 2, FeeRate: 1000},
27+
{Blocks: 6, FeeRate: 1000},
28+
{Blocks: 12, FeeRate: 1000},
29+
{Blocks: 100, FeeRate: 1000},
30+
},
31+
}, nil
32+
}
33+
2234
// try bitcoind first
2335
if bitcoind != nil {
2436
in2, err2 := bitcoind.EstimateSmartFee(2, &btcjson.EstimateModeConservative)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
3232
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
3333
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3434
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
35-
github.com/1ma/lightningd-gjson-rpc v0.0.0-20241109130140-ddc6991a26cf h1:4QFQcuL5Fks+WRI+BSrgTxGoJxNUM/Ht8YCgQRoKcDY=
36-
github.com/1ma/lightningd-gjson-rpc v0.0.0-20241109130140-ddc6991a26cf/go.mod h1:DqVHlrgk0q0J08nbPBCwDVuB7vzPohRnrzuGZ0ct0fg=
3735
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
3836
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
3937
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

integration_test.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,31 @@
11
from pyln.client import RpcError
22
from pyln.testing.fixtures import *
3-
from pyln.testing.utils import wait_for
43

54
def test_bcli(node_factory, bitcoind, chainparams):
65
"""
7-
This tests the bcli plugin, used to gather Bitcoin data from a local
8-
bitcoind.
9-
Mostly sanity checks of the interface...
6+
Based on the test_bcli from Core Lightning
107
"""
11-
12-
l1 = node_factory.get_node()
13-
l2 = node_factory.get_node()
8+
node = node_factory.get_node(opts={
9+
"disable-plugin": "bcli",
10+
"plugin": os.path.join(os.getcwd(), 'trustedcoin'),
11+
})
1412

1513
# We cant stop it dynamically
1614
with pytest.raises(RpcError):
17-
l1.rpc.plugin_stop("bcli")
15+
node.rpc.plugin_stop("bcli")
1816

1917
# Failure case of feerate is tested in test_misc.py
20-
estimates = l1.rpc.call("estimatefees")
18+
estimates = node.rpc.call("estimatefees")
2119
assert 'feerate_floor' in estimates
2220
assert [f['blocks'] for f in estimates['feerates']] == [2, 6, 12, 100]
2321

24-
resp = l1.rpc.call("getchaininfo", {"last_height": 0})
22+
resp = node.rpc.call("getchaininfo", {"last_height": 0})
2523
assert resp["chain"] == chainparams['name']
2624
for field in ["headercount", "blockcount", "ibd"]:
2725
assert field in resp
2826

2927
# We shouldn't get upset if we ask for an unknown-yet block
30-
resp = l1.rpc.call("getrawblockbyheight", {"height": 500})
28+
resp = node.rpc.call("getrawblockbyheight", {"height": 500})
3129
assert resp["blockhash"] is resp["block"] is None
32-
resp = l1.rpc.call("getrawblockbyheight", {"height": 50})
30+
resp = node.rpc.call("getrawblockbyheight", {"height": 50})
3331
assert resp["blockhash"] is not None and resp["blockhash"] is not None
34-
# Some other bitcoind-failure cases for this call are covered in
35-
# tests/test_misc.py
36-
37-
l1.fundwallet(10**5)
38-
l1.connect(l2)
39-
fc = l1.rpc.fundchannel(l2.info["id"], 10**4 * 3)
40-
txo = l1.rpc.call("getutxout", {"txid": fc['txid'], "vout": fc['outnum']})
41-
assert (Millisatoshi(txo["amount"]) == Millisatoshi(10**4 * 3 * 10**3)
42-
and txo["script"].startswith("0020"))
43-
l1.rpc.close(l2.info["id"])
44-
# When output is spent, it should give us null !
45-
wait_for(lambda: l1.rpc.call("getutxout", {
46-
"txid": fc['txid'],
47-
"vout": fc['outnum']
48-
})['amount'] is None)
49-
50-
resp = l1.rpc.call("sendrawtransaction", {"tx": "dummy", "allowhighfees": False})
51-
assert not resp["success"] and "decode failed" in resp["errmsg"]

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func main() {
5959
{Name: "bitcoin-rpcport", Type: "string", Description: "Port to bitcoind RPC (optional).", Default: ""},
6060
{Name: "bitcoin-rpcuser", Type: "string", Description: "Username to bitcoind RPC (optional).", Default: ""},
6161
{Name: "bitcoin-rpcpassword", Type: "string", Description: "Password to bitcoind RPC (optional).", Default: ""},
62+
{Name: "bitcoin-datadir", Type: "string", Description: "-datadir arg for bitcoin-cli. For compatibility with bcli, not actually used.", Default: ""},
6263
},
6364
RPCMethods: []plugin.RPCMethod{
6465
{
@@ -131,7 +132,7 @@ func main() {
131132
Description: "Get the Bitcoin feerate in sat/kilo-vbyte.",
132133
LongDescription: "",
133134
Handler: func(p *plugin.Plugin, params plugin.Params) (resp any, errCode int, err error) {
134-
estfees, err := getFeeRates()
135+
estfees, err := getFeeRates(p.Network)
135136
if err != nil {
136137
p.Logf("estimatefees error: %s", err.Error())
137138
estfees = &EstimatedFees{}

main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const executable = "./trustedcoin"
1212

1313
const getManifestRequest = `{"jsonrpc":"2.0","id":"getmanifest","method":"getmanifest","params":{}}`
14-
const getManifestExpectedResponse = `{"jsonrpc":"2.0","id":"getmanifest","result":{"options":[{"name":"bitcoin-rpcconnect","type":"string","default":"","description":"Hostname (IP) to bitcoind RPC (optional)."},{"name":"bitcoin-rpcport","type":"string","default":"","description":"Port to bitcoind RPC (optional)."},{"name":"bitcoin-rpcuser","type":"string","default":"","description":"Username to bitcoind RPC (optional)."},{"name":"bitcoin-rpcpassword","type":"string","default":"","description":"Password to bitcoind RPC (optional)."}],"rpcmethods":[{"name":"getrawblockbyheight","usage":"height","description":"Get the bitcoin block at a given height","long_description":""},{"name":"getchaininfo","usage":"","description":"Get the chain id, the header count, the block count and whether this is IBD.","long_description":""},{"name":"estimatefees","usage":"","description":"Get the Bitcoin feerate in sat/kilo-vbyte.","long_description":""},{"name":"sendrawtransaction","usage":"tx","description":"Send a raw transaction to the Bitcoin network.","long_description":""},{"name":"getutxout","usage":"txid vout","description":"Get informations about an output, identified by a {txid} an a {vout}","long_description":""}],"subscriptions":[],"hooks":[],"featurebits":{"features":"","channel":"","init":"","invoice":""},"dynamic":false,"notifications":[]}}`
14+
const getManifestExpectedResponse = `{"jsonrpc":"2.0","id":"getmanifest","result":{"options":[{"name":"bitcoin-rpcconnect","type":"string","default":"","description":"Hostname (IP) to bitcoind RPC (optional)."},{"name":"bitcoin-rpcport","type":"string","default":"","description":"Port to bitcoind RPC (optional)."},{"name":"bitcoin-rpcuser","type":"string","default":"","description":"Username to bitcoind RPC (optional)."},{"name":"bitcoin-rpcpassword","type":"string","default":"","description":"Password to bitcoind RPC (optional)."},{"name":"bitcoin-datadir","type":"string","default":"","description":"-datadir arg for bitcoin-cli. For compatibility with bcli, not actually used."}],"rpcmethods":[{"name":"getrawblockbyheight","usage":"height","description":"Get the bitcoin block at a given height","long_description":""},{"name":"getchaininfo","usage":"","description":"Get the chain id, the header count, the block count and whether this is IBD.","long_description":""},{"name":"estimatefees","usage":"","description":"Get the Bitcoin feerate in sat/kilo-vbyte.","long_description":""},{"name":"sendrawtransaction","usage":"tx","description":"Send a raw transaction to the Bitcoin network.","long_description":""},{"name":"getutxout","usage":"txid vout","description":"Get informations about an output, identified by a {txid} an a {vout}","long_description":""}],"subscriptions":[],"hooks":[],"featurebits":{"features":"","channel":"","init":"","invoice":""},"dynamic":false,"notifications":[]}}`
1515

1616
const initRequest = `{"jsonrpc":"2.0","id":"init","method":"init","params":{"options":{},"configuration":{"network":"bitcoin","lightning-dir":"/tmp","rpc-file":"foo"}}}`
1717
const initExpectedResponse = `{"jsonrpc":"2.0","id":"init"}`
@@ -36,12 +36,12 @@ func start(t *testing.T) (*exec.Cmd, io.WriteCloser, io.ReadCloser, io.ReadClose
3636

3737
_, _ = io.WriteString(stdin, getManifestRequest)
3838
if response := readline(stdout); response != getManifestExpectedResponse {
39-
t.Fatalf("unexpected RPC response: %s", response)
39+
t.Fatalf("unexpected manifest response: %s", response)
4040
}
4141

4242
_, _ = io.WriteString(stdin, initRequest)
4343
if response := readline(stdout); response != initExpectedResponse {
44-
t.Fatalf("unexpected RPC response: %s", response)
44+
t.Fatalf("unexpected init response: %s", response)
4545
}
4646

4747
if response := readline(stderr); !strings.Contains(response, "initialized plugin") {

0 commit comments

Comments
 (0)