Esempio n. 1
0
    def test_shortvec_valid(self):
        for i in range(2**16):
            b = bytearray()
            encode_length(b, i)

            actual, _ = decode_length(b)
            assert actual == i
Esempio n. 2
0
    def marshal(self) -> bytes:
        b = bytearray()

        # Signatures
        shortvec.encode_length(b, len(self.signatures))

        for s in self.signatures:
            b.extend(s)

        # Message
        b.extend(self.message.marshal())

        return bytes(b)
Esempio n. 3
0
    def marshal(self) -> bytes:
        b = bytearray()

        # Header
        b.append(self.header.num_signatures)
        b.append(self.header.num_read_only_signed)
        b.append(self.header.num_read_only)

        # Accounts
        shortvec.encode_length(b, len(self.accounts))
        for a in self.accounts:
            b.extend(a.raw)

        # Recent Blockhash
        b.extend(self.recent_blockhash)

        # Instructions
        shortvec.encode_length(b, len(self.instructions))
        for i in self.instructions:
            b.append(i.program_index)

            # Accounts
            shortvec.encode_length(b, len(i.accounts))
            b.extend(i.accounts)

            # Data
            shortvec.encode_length(b, len(i.data))
            b.extend(i.data)

        return bytes(b)
Esempio n. 4
0
 def test_shortvec_invalid(self):
     with pytest.raises(ValueError):
         encode_length(bytearray(), 2**16)
Esempio n. 5
0
 def test_shortvec_cross_impl(self, val, encoded):
     b = bytearray()
     n = encode_length(b, val)
     assert len(encoded) == n
     assert encoded == b