Skip to content

Commit

Permalink
tests/events: spec for test vectors and a simple example.
Browse files Browse the repository at this point in the history
I initially used JSON, but it was not human-writable.  The simple
DSL is much more human-writable, and readable.

This evolved over many (squished) changes, much of the work done
by Lisa Neigut <niftynei@gmail.com>.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Sep 2, 2019
1 parent 8555709 commit 972f5c3
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Implementation Tests for Lightning Specifications

This directory contains conversation-style tests for Lightning
implementations. The format is documented in
[tests/events/test-spec.md](events/test-spec.md), and the base driver for an
implementation is in the [tools/test-events.py](../tools/test-events.py).

To run the tests, you need to write a driver for your particular
implementation, like the one for
[c-lightning](../tools/test-events-clightning.py). Then extract the
format of all messages into a file, like so:

$ python3 tools/extract-formats.py 0*.md > format.csv

Finally, you can run a test like so:

$ tools/test-events-clightning.py formats.csv tests/events/*.events

The `-v` option will give more verbose output, which is particularly
useful when debugging your test script.

Good luck!
Rusty.
58 changes: 58 additions & 0 deletions tests/events/bolt1-01-init.events
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Variations on init exchange.
# Spec: MUST respond to known feature bits as specified in [BOLT #9](09-features.md).

1. connect: privkey=0000000000000000000000000000000000000000000000000000000000000003
2. expect-send: type=init
3. recv: type=init globalfeatures= localfeatures=

1. nothing
1. disconnect:

4. connect: privkey=0000000000000000000000000000000000000000000000000000000000000002
# Even if we don't send anything, it should send init.
1. expect-send: type=init

# Minimal possible init message.
# Spec: MUST send `init` as the first Lightning message for any connection.
1. expect-send: type=init
2. recv: type=init globalfeatures= localfeatures=

# Sanity check that bits 14 and 15 are not used!
1. expect-send: type=init globalfeatures=0000/C000
# init msg with unknown odd global bit (15): no error
2. recv: type=init globalfeatures=8000 localfeatures=

1. expect-send: type=init localfeatures=0000/C000
# init msg with unknown odd local bit (15): no error
2. recv: type=init globalfeatures= localfeatures=8000

# init msg with unknown even global bit (14): you will error
1. expect-send: type=init
2. recv: type=init globalfeatures=4000 localfeatures=
3. expect-error:

# init msg with unknown even local bit (14): you will error
1. expect-send: type=init
2. recv: type=init globalfeatures= localfeatures=4000
3. expect-error:

# If you don't support `option_data_loss_protect`, you will be ok if
# we ask for it.
1. expect-send: type=init localfeatures=00/03 !option_data_loss_protect
2. recv: type=init globalfeatures= localfeatures=02 !option_data_loss_protect

# If you don't support `option_data_loss_protect`, you will error if
# we require it.
1. expect-send: type=init localfeatures=00/03 !option_data_loss_protect
2. recv: type=init globalfeatures= localfeatures=01 !option_data_loss_protect
3. expect-error: !option_data_loss_protect

# If you support `option_data_loss_protect`, you will advertize it odd.
1. expect-send: type=init localfeatures=02/03 option_data_loss_protect/odd

# If you require `option_data_loss_protect`, you will advertize it even.
1. expect-send: type=init localfeatures=01/03 option_data_loss_protect/even

# Note: it's undefined what you'll do if implementation requires
# an option and isn't offered it. The recipient of the required feature
# bit should notice the requirement and error.
81 changes: 81 additions & 0 deletions tests/events/setup.incl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Include this to create channels and set variables for gossip messages.

# BLOCK_102 allows funding of channels with several UTXOs for easy testing.
#
# Here are the keys to spend funds, derived from BIP32 seed
# `0000000000000000000000000000000000000000000000000000000000000001`:
#
# pubkey 0/0/1: 02d6a3c2d0cf7904ab6af54d7c959435a452b24a63194e1c4e7c337d3ebbb3017b
# privkey 0/0/1: 76edf0c303b9e692da9cb491abedef46ca5b81d32f102eb4648461b239cb0f99
# WIF 0/0/1: cRZtHFwyrV3CS1Muc9k4sXQRDhqA1Usgi8r7NhdEXLgM5CUEZufg
# P2WPKH 0/0/1: bcrt1qsdzqt93xsyewdjvagndw9523m27e52er5ca7hm
# UTXO: 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/1 (0.01BTC)
#
# pubkey 0/0/2: 038f1573b4238a986470d250ce87c7a91257b6ba3baf2a0b14380c4e1e532c209d
# privkey 0/0/2: bc2f48a76a6b8815940accaf01981d3b6347a68fbe844f81c50ecbadf27cd179
# WIF 0/0/2: cTtWRYC39drNzaANPzDrgoYsMgs5LkfE5USKH9Kr9ySpEEdjYt3E
# P2WPKH 0/0/2: bcrt1qlkt93775wmf33uacykc49v2j4tayn0yj25msjn
# UTXO: 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/0 (0.02BTC)
#
# pubkey 0/0/3: 02ffef0c295cf7ca3a4ceb8208534e61edf44c606e7990287f389f1ea055a1231c
# privkey 0/0/3: 16c5027616e940d1e72b4c172557b3b799a93c0582f924441174ea556aadd01c
# WIF 0/0/3: cNLxnoJSQDRzXnGPr4ihhy2oQqRBTjdUAM23fHLHbZ2pBsNbqMwb
# P2WPKH 0/0/3: bcrt1q2ng546gs0ylfxrvwx0fauzcvhuz655en4kwe2c
# UTXO: 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/3 (0.03BTC)
#
# pubkey 0/0/4: 026957e53b46df017bd6460681d068e1d23a7b027de398272d0b15f59b78d060a9
# privkey 0/0/4: 53ac43309b75d9b86bef32c5bbc99c500910b64f9ae089667c870c2cc69e17a4
# WIF 0/0/4: cQPMJRjxse9i1jDeCo8H3khUMHYfXYomKbwF5zUqdPrFT6AmtTbd
# P2WPKH 0/0/4: bcrt1qrdpwrlrmrnvn535l5eldt64lxm8r2nwkv0ruxq
# UTXO: 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/4 (0.04BTC)
#
# pubkey 0/0/5: 03a9f795ff2e4c27091f40e8f8277301824d1c3dfa6b0204aa92347314e41b1033
# privkey 0/0/5: 16be98a5d4156f6f3af99205e9bc1395397bca53db967e50427583c94271d27f
# WIF 0/0/5: cNLuxyjvR6ga2q6fdmSKxAd1CPQDShKV9yoA7zFKT7GJwZXr9MmT
# P2WPKH 0/0/5: bcrt1q622lwmdzxxterumd746eu3d3t40pq53p62zhlz
# UTXO: 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/2 (49.89995320BTC)

BLOCK_102=height=102 tx=020000000001017b8705087f9bddd2777021d2a1dfefc2f1c5afa833b5c4ab00ccc8a556d042830000000000feffffff0580841e0000000000160014fd9658fbd476d318f3b825b152b152aafa49bc9240420f000000000016001483440596268132e6c99d44dae2d151dabd9a2b2338496d2901000000160014d295f76da2319791f36df5759e45b15d5e105221c0c62d000000000016001454d14ae910793e930d8e33d3de0b0cbf05aa533300093d00000000001600141b42e1fc7b1cd93a469fa67ed5eabf36ce354dd6024730440220782128cb0319a8430a687c51411e34cfaa6641da9a8f881d8898128cb5c46897022056e82d011a95fd6bcb6d0d4f10332b0b0d1227b2c4ced59e540eb708a4b24e4701210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179865000000

# Funding tx spending 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/1, feerate 253 to bitcoin privkeys 0000000000000000000000000000000000000000000000000000000000000010 and 0000000000000000000000000000000000000000000000000000000000000020 (txid 189c40b0728f382fe91c87270926584e48e0af3a6789f37454afee6c756031
BLOCK_103=height=103 n=6 tx=020000000001016b85f654d8186f4d5dd32a977b2cf8c4b01ff4634152acba16b654c1c85a83160100000000ffffffff01c5410f0000000000220020c46bf3d1686d6dbb2d9244f8f67b90370c5aa2747045f1aeccb77d8187117382024730440220798d96d5a057b5b7797988a855217f41af05ece3ba8278366e2f69763c72e785022065d5dd7eeddc0766ddf65557c92b9c52c301f23f94d2cf681860d32153e6ae1e012102d6a3c2d0cf7904ab6af54d7c959435a452b24a63194e1c4e7c337d3ebbb3017b00000000

# This channel claimed by nodeids with privkeys ...002 and ...003.
CHAN_ANN_103x1x0=type=channel_announcement node_signature_1=63023be1b5b1f9fbb26fde890032bf4098fba6a78be75a8dd9deae332f6d20ec634806cc3477c41ca565c45089a8331beb3912fb896188b117d525ee17c85f63 node_signature_2=7f2c0664c6205e3c9626b4b7618d18235c059f13579a41dd79ae99e1234d5e8709d295e77c3846b37c44edc7fc4bd1ab07b605c0d216973b6bb4d9dead54b98e bitcoin_signature_1=083ccfe5a766dfe236446ddf52a4f89da5d3f3acc06851f2b0821223a069be02005f5cae7747451b8ae53709723c50fef2c7861c1b8b6bba1043e5bde56dbc39 bitcoin_signature_2=157a587d3495da5b953ba4a9f3a6ad8479a114e4bacbf4262dc257dd86f10db949e6e34e12ef95ead4ba5a9e38b86cd530920b7054914f1ee61ed4261783aa12 features= chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=103x1x0 node_id_1=02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 node_id_2=02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 bitcoin_key_1=03e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a bitcoin_key_2=03d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65

CHAN_UPDATE_103x1x0_002=type=channel_update signature=76df7e70c63cc2b63ef1c062b99c6d934a80ef2fd4dae9e1d86d277f47674af3255a97fa52ade7f129263f591ed784996eba6383135896cc117a438c80293282 chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=103x1x0 timestamp=1565587763 message_flags=0 channel_flags=0 cltv_expiry_delta=144 htlc_minimum_msat=0 fee_base_msat=1000 fee_proportional_millionths=10

NODE_ANN_002=type=node_announcement signature=f48cc073f61994f978d6fc483cf477bdfd5c754d5deaf055af161fda9039831469432b5d4a08e95242498accf7324dc5918c8efe33dc5c65e17c90121c13320b features= timestamp=1565587763 node_id=02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 rgb_color=02c604 alias=3032633630343766393434316564376436643330343534303665393563303763 addresses=01080808082607

CHAN_UPDATE_103x1x0_003=type=channel_update signature=0b20265c60b98d6150097ea2ed73a0df4c870ed13defde348c799dd418671ca814837b7b46733d3f28f63b4f36768b44f6ec8dc52fbb08103e27c85ab1188c60 chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=103x1x0 timestamp=1565587763 message_flags=1 channel_flags=1 cltv_expiry_delta=48 htlc_minimum_msat=0 fee_base_msat=100 fee_proportional_millionths=11 htlc_maximum_msat=100000

NODE_ANN_003=type=node_announcement signature=d0b8131bac61b20ecfd04f4ddd7042b98e140bc43ed5ab362ac29516bf0e7fce2c92b1e0f39de68afca2ab8cd1d1205a4847f3116c210b9352fba2d628c9b458 features= timestamp=1565587763 node_id=02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 rgb_color=02f930 alias=3032663933303861303139323538633331303439333434663835663839643532 addresses=0151b6887026070220014c4e1cc141001e6f65fffec8a825260703c43068ceb641d7b25c3a26070441cf248da2034dfa9351a9e946d71ce86f561f50b67753fd8e385d44647bf62cdb91032607

# A later node-announcement, a little different.
NODE_ANN_003_LATER=type=node_announcement signature=9accff5a0d434eb09b5a3b594af3adc675e223f200a2d488947c6fca39115c885bf87b69963bcac430d0267ef15fe6f7abfa84d4b9be2bb0ee17822d1c02af41 features= timestamp=1565597764 node_id=02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 rgb_color=02f930 alias=3032663933303861303139323538633331303439333434663835663839643532 addresses=0441cf248da2034dfa9351a9e946d71ce86f561f50b67753fd8e385d44647bf62cdb91032607

# Funding tx spending 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/0, feerate 253 to bitcoin privkeys 0000000000000000000000000000000000000000000000000000000000000030 and 0000000000000000000000000000000000000000000000000000000000000040 (txid db029ee8cc511625887c192c5bb264249fe69b9b86eb627a52f9a313ba231ade)
BLOCK_109=height=109 n=6 tx=020000000001016b85f654d8186f4d5dd32a977b2cf8c4b01ff4634152acba16b654c1c85a83160000000000ffffffff0105841e0000000000220020fa73be60259cea454ee79a963514f0b7622db62eadc88daafe377bfa2aa30fbb0247304402205735b9750a90be1ca09cdf91d6697bde3746a390698ca754d516b56c72880bae02203c1deef3645cc20e300db1a808ffc7c2f57be200761ee3cf1a479d1e1aef70bc0121038f1573b4238a986470d250ce87c7a91257b6ba3baf2a0b14380c4e1e532c209d00000000

# This channel claimed by nodeids with privkeys ...004 and ...005.
CHAN_ANN_109x1x0=type=channel_announcement node_signature_1=764be32b3a8839a171a8ad9ef25d326d5c58160029006733ea06978e2806789024a1516575f69c957db8beeb3e5e1452e48db1b3ee085f3d623b47a986539783 node_signature_2=4f71e2785eb9d3833f307f8d954bc7b80f47bdcf483ff41ed9354143dbf62e1b50e31b9f735a26dc1d1ae78e857e0e727761faeaf60c9326cffd232f6ffd74e6 bitcoin_signature_1=8dd1cc39900c5728645b8a031e614b491abb36ff2aa3b529da7bce7091f28d6f237358c168f38a933ed483d9d582af45ee2b078ac9174751a9a4613c3fe4e8e7 bitcoin_signature_2=0bde268ccf1f1e7b245cd23d68e8bda0cb2fe42672bbe693a6a5cf85033fadbe069330dc785665ce8306946d00c16e40035e99db3daf4e1a087ca655f093b14a features= chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=109x1x0 node_id_1=022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 node_id_2=02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 bitcoin_key_1=03bf23c1542d16eab70b1051eaf832823cfc4c6f1dcdbafd81e37918e6f874ef8b bitcoin_key_2=026eca335d9645307db441656ef4e65b4bfc579b27452bebc19bd870aa1118e5c3

CHAN_UPDATE_109x1x0_004=type=channel_update signature=e4328bdcc06a311030d494ee391e000ca8bcdff59f0d071fce10253d43ba65e778c0540c11fb6417a43031da25c5a7b2c38122e92a7111760261967802128219 chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=109x1x0 timestamp=1565587764 message_flags=0 channel_flags=1 cltv_expiry_delta=144 htlc_minimum_msat=0 fee_base_msat=1000 fee_proportional_millionths=10

NODE_ANN_004=type=node_announcement signature=189a566e9718c5ead7ac99956c0297b56c54bb304c99d3f02235712a376ad09f683cdd8d94d3c71c82fae2a08ea2495cca31426b6d4ec5ac35e83361c15633ef features= timestamp=1565587764 node_id=02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 rgb_color=02e493 alias=3032653439336462663163313064383066333538316534393034393330623134 addresses=

NODE_ANN_004_LATER=type=node_announcement signature=3370d9ada9e7b19e81425b32c2f05c5acb650f7ecb45ddb16eec922b1af956c23df932d7b13f6e7e0f230b1565df6ae7e0f7c4251d9a6805e3ef6057dd467cac features= timestamp=1565597765 node_id=02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 rgb_color=02e493 alias=3032653439336462663163313064383066333538316534393034393330623134 addresses=

CHAN_UPDATE_109x1x0_005=type=channel_update signature=06737e9e18d3e4d0ab4066ccaecdcc10e648c5f1c5413f1610747e0d463fa7fa39c1b02ea2fd694275ecfefe4fe9631f24afd182ab75b805e16cd550941f858c chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=109x1x0 timestamp=1565587765 message_flags=1 channel_flags=0 cltv_expiry_delta=48 htlc_minimum_msat=0 fee_base_msat=100 fee_proportional_millionths=11 htlc_maximum_msat=100000

NODE_ANN_005=type=node_announcement signature=7a553b3933cb5974997c3e294a46ea474a435df2c0d82a0732c0c9700b04e2a6492b2a0620dcfd68e8e64c35b867bc3ec5df4393e3fc3b397095768e2362bae2 features= timestamp=1565587765 node_id=022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 rgb_color=022f8b alias=3032326638626465346431613037323039333535623461373235306135633531 addresses=022a03b0c0000300d000000000240020012607

# Funding tx spending 16835ac8c154b616baac524163f41fb0c4f82c7b972ad35d4d6f18d854f6856b/3, feerate 253 to bitcoin privkeys 0000000000000000000000000000000000000000000000000000000000000050 and 0000000000000000000000000000000000000000000000000000000000000060 (txid 03330f41079aba9a595310c9c4d78676e5291ee6f1931dd7686f46ed16096186)
BLOCK_115=height=115 n=6 tx=020000000001016b85f654d8186f4d5dd32a977b2cf8c4b01ff4634152acba16b654c1c85a83160300000000ffffffff0145c62d00000000002200208225164b456194e9721a5ff5ea4df731d3d663f48f3ba96961dc9d0617ea2bf20247304402200bf2e7a300f8d268c9480732748707b36e43f6225f5330eca2cfa00b21c7159a02205390a3469a14b3a48714bb44db6d8ee838ef5e29b3063a32cba22a3a2d4f3e00012102ffef0c295cf7ca3a4ceb8208534e61edf44c606e7990287f389f1ea055a1231c00000000

# This channel claimed by nodeids with privkeys ...003 and ...004.
CHAN_ANN_115x1x0=type=channel_announcement node_signature_1=91d93a0ac557d03c0cb78b7699ad70ab2e86aed6e1780bd5381637bedbfe202938109484eee1a36a33aa7e0149fa062c502261564e4ecdbebdad5d32657efb82 node_signature_2=dc8cfdb6cdcde9e760f6b21f4d6ce7fe7569143aa253e1ae5339d96b9654422715ca0909f50b612818f9bb9e91fa4729d80d9fe3c16a9af821260a2c1c91888e bitcoin_signature_1=57543ea23aae8231dbe25a89ad1e6d32a4d17f27a84402d7535ec6af3d5c185645d98f605737bc7367660e6084f3d3a2ed2c8a6401feb71057d48f2de5f0961f bitcoin_signature_2=f19424a474fe2d1b573333d0783591a5478616d498f3331d6d0f32f570bce84862731442f0b1d04fa8f94a3bd639e8e7cb1ad5e96795b36f538ab45a90da4a90 features= chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=115x1x0 node_id_1=02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 node_id_2=02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 bitcoin_key_1=033f0e80e574456d8f8fa64e044b2eb72ea22eb53fe1efe3a443933aca7f8cb0e3 bitcoin_key_2=03e9623bbef1bf90ec0d7c744ed34659f010e6e638637161270ecd31e14f87f62e

CHAN_UPDATE_115x1x0_003=type=channel_update signature=d920087673273a3221e6bf8671e1e3e0b20319c5dd87233c6525a90acaded2c032386032657daccf33e08e9aeb5a590300eb58a3943a89e73814bbf930d72391 chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=115x1x0 timestamp=1565597764 message_flags=0 channel_flags=1 cltv_expiry_delta=144 htlc_minimum_msat=0 fee_base_msat=1000 fee_proportional_millionths=10

CHAN_UPDATE_115x1x0_004=type=channel_update signature=ca7bb2adea595eeb448c0139136196557f9f7b52ea0e3d85634bf8d7dd99096440e06e55d2874506ab6dd8d3b9285c0282dae498cb33146314084e37dbf2cff3 chain_hash=06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f short_channel_id=115x1x0 timestamp=1565597765 message_flags=1 channel_flags=0 cltv_expiry_delta=48 htlc_minimum_msat=0 fee_base_msat=100 fee_proportional_millionths=11 htlc_maximum_msat=100000
Loading

0 comments on commit 972f5c3

Please sign in to comment.