|
| 1 | +// SPDX-License-Identifier: Apache-2.0 OR MIT |
| 2 | +pragma solidity ^0.8.30; |
| 3 | + |
| 4 | +import {MockFVMTest} from "../src/mocks/MockFVMTest.sol"; |
| 5 | +import {FVMAddress} from "../src/FVMAddress.sol"; |
| 6 | + |
| 7 | +contract AddressTest is MockFVMTest { |
| 8 | + using FVMAddress for uint64; |
| 9 | + |
| 10 | + function testLookupDelegatedAddressNotFound() public view { |
| 11 | + uint64 fakeActorId = 99999; |
| 12 | + (bool success, bytes memory delegatedAddress) = FVMAddress.lookupDelegatedAddress(fakeActorId); |
| 13 | + assertTrue(success); |
| 14 | + assertEq(delegatedAddress.length, 0); |
| 15 | + } |
| 16 | + |
| 17 | + function testLookupDelegatedAddressMocked() public { |
| 18 | + uint64 testActorId = 54321; |
| 19 | + bytes memory expectedAddress = hex"040a1234567890abcdef1234567890abcdef1234"; |
| 20 | + |
| 21 | + LOOKUP_DELEGATED_ADDRESS_PRECOMPILE.mockLookupDelegatedAddress(testActorId, expectedAddress); |
| 22 | + |
| 23 | + (bool success, bytes memory delegatedAddress) = FVMAddress.lookupDelegatedAddress(testActorId); |
| 24 | + assertTrue(success); |
| 25 | + assertEq(delegatedAddress, expectedAddress); |
| 26 | + } |
| 27 | + |
| 28 | + function testActorIdToEthAddress() public { |
| 29 | + uint64 testActorId = 11111; |
| 30 | + address expectedEthAddress = address(0x1234567890AbcdEF1234567890aBcdef12345678); |
| 31 | + |
| 32 | + LOOKUP_DELEGATED_ADDRESS_PRECOMPILE.mockActorIdToEthAddress(testActorId, expectedEthAddress); |
| 33 | + |
| 34 | + (bool success, address ethAddress) = FVMAddress.actorIdToEthAddress(testActorId); |
| 35 | + assertTrue(success); |
| 36 | + assertEq(ethAddress, expectedEthAddress); |
| 37 | + } |
| 38 | + |
| 39 | + function testActorIdToEthAddressNotFound() public view { |
| 40 | + uint64 fakeActorId = 99999; |
| 41 | + (bool success, address ethAddress) = FVMAddress.actorIdToEthAddress(fakeActorId); |
| 42 | + assertFalse(success); |
| 43 | + assertEq(ethAddress, address(0)); |
| 44 | + } |
| 45 | + |
| 46 | + function testActorIdToEthAddressInvalidPrefix() public { |
| 47 | + uint64 testActorId = 22222; |
| 48 | + bytes memory invalidAddress = hex"ff0a1234567890abcdef1234567890abcdef1234"; |
| 49 | + |
| 50 | + LOOKUP_DELEGATED_ADDRESS_PRECOMPILE.mockLookupDelegatedAddress(testActorId, invalidAddress); |
| 51 | + |
| 52 | + (bool success, address ethAddress) = FVMAddress.actorIdToEthAddress(testActorId); |
| 53 | + assertFalse(success); |
| 54 | + assertEq(ethAddress, address(0)); |
| 55 | + } |
| 56 | + |
| 57 | + function testActorIdToEthAddressWrongLength() public { |
| 58 | + uint64 testActorId = 33333; |
| 59 | + bytes memory shortAddress = hex"040a12345678"; |
| 60 | + |
| 61 | + LOOKUP_DELEGATED_ADDRESS_PRECOMPILE.mockLookupDelegatedAddress(testActorId, shortAddress); |
| 62 | + |
| 63 | + (bool success, address ethAddress) = FVMAddress.actorIdToEthAddress(testActorId); |
| 64 | + assertFalse(success); |
| 65 | + assertEq(ethAddress, address(0)); |
| 66 | + } |
| 67 | +} |
0 commit comments