Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_getCode to return the redirect bytecode for HTS tokens #598

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,9 @@ export class EthImpl implements Eth {
}

private static redirectBytecodeAddressReplace(address: string): string {
return `6080604052348015600f57600080fd5b506000610167905077618dc65e${address.slice(2)}600052366000602037600080366018016008845af43d806000803e8160008114605857816000f35b816000fdfea2646970667358221220d8378feed472ba49a0005514ef7087017f707b45fb9bf56bb81bb93ff19a238b64736f6c634300080b0033`
const redirectBytecodePrefix = '6080604052348015600f57600080fd5b506000610167905077618dc65e';
Nana-EC marked this conversation as resolved.
Show resolved Hide resolved
const redirectBytecodePostfix = '600052366000602037600080366018016008845af43d806000803e8160008114605857816000f35b816000fdfea2646970667358221220d8378feed472ba49a0005514ef7087017f707b45fb9bf56bb81bb93ff19a238b64736f6c634300080b0033';
return `${redirectBytecodePrefix}${address.slice(2)}${redirectBytecodePostfix}`;
}

/**
Expand Down
70 changes: 70 additions & 0 deletions packages/relay/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,76 @@ const mockData = {
}
},

tokenId: '0.0.13312',
token: {
"admin_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"auto_renew_account": "0.1.2",
"auto_renew_period": null,
"created_timestamp": "1234567890.000000001",
"deleted": false,
"decimals": 1000,
"expiry_timestamp": null,
"freeze_default": false,
"freeze_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"initial_supply": 1000000,
"kyc_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"max_supply": 9223372036854776000,
"memo": "token memo",
"modified_timestamp": "1234567890.000000001",
"name": "Token name",
"pause_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"pause_status": "UNPAUSED",
"supply_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"supply_type": "INFINITE",
"symbol": "ORIGINALRDKSE",
"token_id": "0.0.13312",
"total_supply": 1000000,
"treasury_account_id": "0.1.2",
"type": "FUNGIBLE_COMMON",
"wipe_key": {
"_type": "ProtobufEncoded",
"key": 10101
},
"custom_fees": {
"created_timestamp": "1234567890.000000001",
"fixed_fees": [
{
"amount": 100,
"collector_account_id": "0.1.5",
"denominating_token_id": "0.10.8"
}
],
"fractional_fees": [
{
"amount": {
"numerator": 12,
"denominator": 29
},
"collector_account_id": "0.1.6",
"denominating_token_id": "0.10.9",
"maximum": 120,
"minimum": 30,
"net_of_transfers": true
}
]
}
},

notFound: {
"_status": {
"messages": [
Expand Down
35 changes: 34 additions & 1 deletion packages/relay/tests/lib/mirrorNodeClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ describe('MirrorNodeClient', async function () {
expect(result).to.be.null;
});

it('`getTokenById`', async () => {
mock.onGet(`tokens/${mockData.tokenId}`).reply(200, mockData.token);

const result = await mirrorNodeInstance.getTokenById(mockData.tokenId);
expect(result).to.exist;
expect(result.token_id).equal('0.0.13312');
});

it('`getTokenById` not found', async () => {
const tokenId = '0.0.132';
mock.onGet(`accounts/${tokenId}`).reply(404, mockData.notFound);

const result = await mirrorNodeInstance.getTokenById(tokenId);
expect(result).to.be.null;
});

const detailedContractResult = {
'access_list': '0x',
'amount': 2000000000,
Expand Down Expand Up @@ -532,6 +548,7 @@ describe('MirrorNodeClient', async function () {
it('returns `contract` when CONTRACTS endpoint returns a result', async() => {
mock.onGet(`contracts/${mockData.contractEvmAddress}`).reply(200, mockData.contract);
mock.onGet(`accounts/${mockData.contractEvmAddress}`).reply(200, mockData.account);
mock.onGet(`tokens/${mockData.tokenId}`).reply(404, mockData.notFound);

const entityType = await mirrorNodeInstance.resolveEntityType(mockData.contractEvmAddress);
expect(entityType).to.exist;
Expand All @@ -542,9 +559,10 @@ describe('MirrorNodeClient', async function () {
expect(entityType.entity.contract_id).to.eq(mockData.contract.contract_id);
});

it('returns `account` when CONTRACTS endpoint returns 404 and ACCOUNTS endpoint returns a result', async() => {
it('returns `account` when CONTRACTS and TOKENS endpoint returns 404 and ACCOUNTS endpoint returns a result', async() => {
mock.onGet(`contracts/${mockData.contractEvmAddress}`).reply(404, mockData.notFound);
mock.onGet(`accounts/${mockData.contractEvmAddress}`).reply(200, mockData.account);
mock.onGet(`tokens/${mockData.tokenId}`).reply(404, mockData.notFound);

const entityType = await mirrorNodeInstance.resolveEntityType(mockData.contractEvmAddress);
expect(entityType).to.exist;
Expand All @@ -555,9 +573,24 @@ describe('MirrorNodeClient', async function () {
expect(entityType.entity.account).to.eq(mockData.account.account);
});

it('returns `token` when CONTRACTS and ACCOUNTS endpoints returns 404 and TOKEN endpoint returns a result', async() => {
mock.onGet(`contracts/${mockData.contractEvmAddress}`).reply(404, mockData.notFound);
mock.onGet(`accounts/${mockData.contractEvmAddress}`).reply(404, mockData.notFound);
mock.onGet(`tokens/${mockData.tokenId}`).reply(200, mockData.token);

const entityType = await mirrorNodeInstance.resolveEntityType(mockData.tokenId);
expect(entityType).to.exist;
expect(entityType).to.have.property('type');
expect(entityType).to.have.property('entity');
expect(entityType.type).to.eq('token');
expect(entityType.entity).to.have.property('token');
expect(entityType.entity.token_id).to.eq(mockData.tokenId);
});

it('returns null when CONTRACTS and ACCOUNTS endpoints return 404', async() => {
mock.onGet(`contracts/${mockData.contractEvmAddress}`).reply(404, mockData.notFound);
mock.onGet(`accounts/${mockData.contractEvmAddress}`).reply(404, mockData.notFound);
mock.onGet(`tokens/${mockData.tokenId}`).reply(404, mockData.notFound);

const entityType = await mirrorNodeInstance.resolveEntityType(mockData.contractEvmAddress);
expect(entityType).to.be.null;
Expand Down