def test_ReferenceType_decode(): encoded = pt.Bytes("encoded") for value in (abi.Account(), abi.Asset(), abi.Application()): for start_index in (None, pt.Int(1)): for end_index in (None, pt.Int(2)): for length in (None, pt.Int(3)): expr = value.decode( encoded, start_index=start_index, end_index=end_index, length=length, ) assert expr.type_of() == pt.TealType.none assert expr.has_return() is False expected_decoding = value.stored_value.store( pt.GetByte( encoded, start_index if start_index is not None else pt.Int(0), )) expected, _ = expected_decoding.__teal__(options) expected.addIncoming() expected = pt.TealBlock.NormalizeBlocks(expected) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected
def test_Account_params(): value = abi.Account() params = value.params() assert type(params) is pt.AccountParamObject expected = value.referenced_index() actual = params._account with pt.TealComponent.Context.ignoreExprEquality(): assert actual.__teal__(options) == expected.__teal__(options)
def test_Asset_holding(): value = abi.Asset() accounts = ( (pt.Int(6), pt.Int(6)), ( pt.Addr( "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"), pt.Addr( "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"), ), (a := abi.Account(), a.referenced_index()), )
def test_ReferenceType_referenced_index(): for value in (abi.Account(), abi.Asset(), abi.Application()): expr = value.referenced_index() assert expr.type_of() == pt.TealType.uint64 assert expr.has_return() is False expected = pt.TealSimpleBlock([ pt.TealOp(expr, pt.Op.load, value.stored_value.slot), ]) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected
def test_Account_address(): value = abi.Account() expr = value.address() assert expr.type_of() == pt.TealType.bytes assert expr.has_return() is False expected = pt.TealSimpleBlock([ pt.TealOp(None, pt.Op.load, value.stored_value.slot), pt.TealOp(None, pt.Op.txnas, "Accounts"), ]) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected
def test_Account_typespec(): assert abi.Account().type_spec() == abi.AccountTypeSpec()
def test_ReferenceType_encode(): for value in (abi.Account(), abi.Asset(), abi.Application()): with pytest.raises(pt.TealInputError, match=r"A ReferenceType cannot be encoded$"): value.encode()
def test_Account_asset_holding(): value = abi.Account() assets = ((pt.Int(6), pt.Int(6)), (a := abi.Asset(), a.referenced_index()))