MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_dynamic_array

Function test_dynamic_array

contrib/pyln-proto/tests/test_message.py:204–231  ·  view source on GitHub ↗

Test that dynamic array types enforce matching lengths

()

Source from the content-addressed store, hash-verified

202
203
204def test_dynamic_array():
205 """Test that dynamic array types enforce matching lengths"""
206 ns = MessageNamespace(['msgtype,test1,1',
207 'msgdata,test1,count,u16,',
208 'msgdata,test1,arr1,byte,count',
209 'msgdata,test1,arr2,u32,count'])
210
211 # This one is fine.
212 m = Message(ns.get_msgtype('test1'),
213 arr1='01020304', arr2='[1,2,3,4]')
214 buf = io.BytesIO()
215 m.write(buf)
216 assert buf.getvalue() == bytes([0, 1]
217 + [0, 4]
218 + [1, 2, 3, 4]
219 + [0, 0, 0, 1,
220 0, 0, 0, 2,
221 0, 0, 0, 3,
222 0, 0, 0, 4])
223
224 # These ones are not
225 with pytest.raises(ValueError, match='Inconsistent length.*count'):
226 m = Message(ns.get_msgtype('test1'),
227 arr1='01020304', arr2='[1,2,3]')
228
229 with pytest.raises(ValueError, match='Inconsistent length.*count'):
230 m = Message(ns.get_msgtype('test1'),
231 arr1='01020304', arr2='[1,2,3,4,5]')

Callers

nothing calls this directly

Calls 4

get_msgtypeMethod · 0.95
writeMethod · 0.95
MessageNamespaceClass · 0.90
MessageClass · 0.90

Tested by

no test coverage detected