ARC4 Types¶
These types are available under the algopy.arc4
namespace. Refer to the ARC4 specification for more details on the spec.
Hint
Test context manager provides value generators for ARC4 types. To access their value generators, use {context_instance}.any.arc4
property. See more examples below.
Note
For all algopy.arc4
types with and without respective value generator, instantiation can be performed directly. If you have a suggestion for a new value generator implementation, please open an issue in the algorand-python-testing
repository or contribute by following the contribution guide.
Unsigned Integers¶
from algopy import arc4
# Integer types
uint8_value = arc4.UInt8(255)
uint16_value = arc4.UInt16(65535)
uint32_value = arc4.UInt32(4294967295)
uint64_value = arc4.UInt64(18446744073709551615)
... # instantiate test context
# Generate a random unsigned arc4 integer with default range
uint8 = context.any.arc4.uint8()
uint16 = context.any.arc4.uint16()
uint32 = context.any.arc4.uint32()
uint64 = context.any.arc4.uint64()
biguint128 = context.any.arc4.biguint128()
biguint256 = context.any.arc4.biguint256()
biguint512 = context.any.arc4.biguint512()
# Generate a random unsigned arc4 integer with specified range
uint8_custom = context.any.arc4.uint8(min_value=10, max_value=100)
uint16_custom = context.any.arc4.uint16(min_value=1000, max_value=5000)
uint32_custom = context.any.arc4.uint32(min_value=100000, max_value=1000000)
uint64_custom = context.any.arc4.uint64(min_value=1000000000, max_value=10000000000)
biguint128_custom = context.any.arc4.biguint128(min_value=1000000000000000, max_value=10000000000000000)
biguint256_custom = context.any.arc4.biguint256(min_value=1000000000000000000000000, max_value=10000000000000000000000000)
biguint512_custom = context.any.arc4.biguint512(min_value=10000000000000000000000000000000000, max_value=10000000000000000000000000000000000)
Address¶
from algopy import arc4
# Address type
address_value = arc4.Address("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ")
# Generate a random address
random_address = context.any.arc4.address()
# Access native underlaying type
native = random_address.native
Dynamic Bytes¶
from algopy import arc4
# Dynamic byte string
bytes_value = arc4.DynamicBytes(b"Hello, Algorand!")
# Generate random dynamic bytes
random_dynamic_bytes = context.any.arc4.dynamic_bytes(n=123) # n is the number of bits in the arc4 dynamic bytes
String¶
from algopy import arc4
# UTF-8 encoded string
string_value = arc4.String("Hello, Algorand!")
# Generate random string
random_string = context.any.arc4.string(n=12) # n is the number of bits in the arc4 string