@@ -21,6 +21,16 @@ import { generateEthTestEnv } from './eth-helpers';
21
21
22
22
use ( chaiAsPromised ) ;
23
23
24
+ function entityIdToEvmAddress ( entityId : string ) : string {
25
+ const pad = ( num : string , n : number ) =>
26
+ Number ( num )
27
+ . toString ( 16 )
28
+ . padStart ( n * 2 , '0' ) ;
29
+ const [ shardNum , realmNum , accountNum ] = entityId . split ( '.' ) ;
30
+
31
+ return `0x${ pad ( shardNum , 4 ) } ${ pad ( realmNum , 8 ) } ${ pad ( accountNum , 8 ) } ` ;
32
+ }
33
+
24
34
describe ( '@ethGetCode using MirrorNode' , async function ( ) {
25
35
this . timeout ( 10000 ) ;
26
36
const { restMock, ethImpl, cacheService } = generateEthTestEnv ( ) ;
@@ -95,11 +105,8 @@ describe('@ethGetCode using MirrorNode', async function () {
95
105
restMock . onGet ( `contracts/${ HTS_TOKEN_ADDRESS } ` ) . reply ( 404 , JSON . stringify ( null ) ) ;
96
106
restMock . onGet ( `accounts/${ HTS_TOKEN_ADDRESS } ?limit=100` ) . reply ( 404 , JSON . stringify ( null ) ) ;
97
107
restMock . onGet ( `tokens/0.0.${ parseInt ( HTS_TOKEN_ADDRESS , 16 ) } ` ) . reply ( 200 , JSON . stringify ( DEFAULT_HTS_TOKEN ) ) ;
98
- const redirectBytecode = `6080604052348015600f57600080fd5b506000610167905077618dc65e${ HTS_TOKEN_ADDRESS . slice (
99
- 2 ,
100
- ) } 600052366000602037600080366018016008845af43d806000803e8160008114605857816000f35b816000fdfea2646970667358221220d8378feed472ba49a0005514ef7087017f707b45fb9bf56bb81bb93ff19a238b64736f6c634300080b0033`;
101
108
const res = await ethImpl . getCode ( HTS_TOKEN_ADDRESS , null , requestDetails ) ;
102
- expect ( res ) . to . equal ( redirectBytecode ) ;
109
+ expect ( res ) . to . be . equal ( EthImpl . redirectBytecodeAddressReplace ( HTS_TOKEN_ADDRESS ) ) ;
103
110
} ) ;
104
111
105
112
it ( 'should return the static bytecode for address(0x167) call' , async ( ) => {
@@ -214,10 +221,7 @@ describe('@ethGetCode using MirrorNode', async function () {
214
221
) ;
215
222
216
223
const res = await ethImpl . getCode ( HTS_TOKEN_ADDRESS , blockNumberAfterCreation , requestDetails ) ;
217
- const expectedRedirectBytecode = `6080604052348015600f57600080fd5b506000610167905077618dc65e${ HTS_TOKEN_ADDRESS . slice (
218
- 2 ,
219
- ) } 600052366000602037600080366018016008845af43d806000803e8160008114605857816000f35b816000fdfea2646970667358221220d8378feed472ba49a0005514ef7087017f707b45fb9bf56bb81bb93ff19a238b64736f6c634300080b0033`;
220
- expect ( res ) . to . equal ( expectedRedirectBytecode ) ;
224
+ expect ( res ) . to . be . equal ( EthImpl . redirectBytecodeAddressReplace ( HTS_TOKEN_ADDRESS ) ) ;
221
225
} ) ;
222
226
223
227
it ( 'should throw error for invalid block number' , async ( ) => {
@@ -262,5 +266,16 @@ describe('@ethGetCode using MirrorNode', async function () {
262
266
const res = await ethImpl . getCode ( CONTRACT_ADDRESS_1 , 'earliest' , requestDetails ) ;
263
267
expect ( res ) . to . equal ( EthImpl . emptyHex ) ;
264
268
} ) ;
269
+
270
+ it ( 'should return redirect bytecode for HTS when accountId has non-zero shard/realm' , async function ( ) {
271
+ const accountId = '1.2.3' ;
272
+ const addr = entityIdToEvmAddress ( accountId ) ;
273
+
274
+ restMock . onGet ( `contracts/${ addr } ` ) . reply ( 404 , JSON . stringify ( null ) ) ;
275
+ restMock . onGet ( `accounts/${ addr } ?limit=100` ) . reply ( 404 , JSON . stringify ( null ) ) ;
276
+ restMock . onGet ( `tokens/${ accountId } ` ) . reply ( 200 , JSON . stringify ( DEFAULT_HTS_TOKEN ) ) ;
277
+ const res = await ethImpl . getCode ( addr , null , requestDetails ) ;
278
+ expect ( res ) . to . be . equal ( EthImpl . redirectBytecodeAddressReplace ( addr ) ) ;
279
+ } ) ;
265
280
} ) ;
266
281
} ) ;
0 commit comments