Skip to content

Commit

Permalink
chore: resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: nikolay <[email protected]>
  • Loading branch information
natanasow committed Jan 8, 2025
1 parent 68fce9a commit bc38bcd
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 53 deletions.
6 changes: 4 additions & 2 deletions tools/layer-zero-example/contracts/ExampleOApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ contract ExampleOApp is OApp {
* @param _origin A struct containing information about where the packet came from.
* @param _guid A global unique identifier for tracking the packet.
* @param payload Encoded message.
* @param address Executor address as specified by the OApp.
* @param calldata Any extra data or options to trigger on receipt.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata payload,
address, // Executor address as specified by the OApp.
bytes calldata // Any extra data or options to trigger on receipt.
address,
bytes calldata
) internal override {
// Decode the payload to get the message
// In this case, type is string, but depends on your encoding!
Expand Down
30 changes: 30 additions & 0 deletions tools/layer-zero-example/test/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*-
*
* Hedera JSON RPC Relay - Hardhat Example
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

module.exports = {
// we're using the official LZ endpoints
// and a list of all EIDs can be found here
// EIDs are defined in the layer zero documentation https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts#contract-address-table
HEDERA_EID: 40285,
BSC_EID: 40102,

// a random account
RECEIVER_ADDRESS: '0xF51c7a9407217911d74e91642dbC58F18E51Deac'
};
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/htsAdapterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;
const amount = '100';

describe('HTSAdapterTests', function() {
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('HTSAdapterTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -93,7 +92,7 @@ describe('HTSAdapterTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -119,7 +118,7 @@ describe('HTSAdapterTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.HTS_ADAPTER_HTS_HEDERA_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) adapter balance: ${await contractERC20.balanceOf(process.env.HTS_ADAPTER_HEDERA_CONTRACT)}`);
Expand All @@ -132,7 +131,7 @@ describe('HTSAdapterTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.HTS_ADAPTER_ERC20_BSC_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) adapter balance: ${await contractERC20.balanceOf(process.env.HTS_ADAPTER_BSC_CONTRACT)}`);
Expand Down
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/htsConnectorTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;
const amount = '100';

describe('HTSConnectorTests', function() {
Expand All @@ -46,7 +45,7 @@ describe('HTSConnectorTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -73,7 +72,7 @@ describe('HTSConnectorTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand Down Expand Up @@ -102,7 +101,7 @@ describe('HTSConnectorTests', function() {
const tokenAddress = await oftHts.htsTokenAddress();

const contract = await ethers.getContractAt('ERC20', tokenAddress);
const receiverBalance = await contract.balanceOf(receiverAddress);
const receiverBalance = await contract.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) oft contract balance: ${await contract.balanceOf(process.env.HTS_CONNECTOR_HEDERA_CONTRACT)}`);
console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
Expand All @@ -116,7 +115,7 @@ describe('HTSConnectorTests', function() {
const signers = await ethers.getSigners();

const contract = await ethers.getContractAt('ERC20', process.env.HTS_CONNECTOR_BSC_CONTRACT);
const receiverBalance = await contract.balanceOf(receiverAddress);
const receiverBalance = await contract.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) oft contract balance: ${await contract.balanceOf(process.env.HTS_CONNECTOR_BSC_CONTRACT)}`);
console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
Expand Down
4 changes: 2 additions & 2 deletions tools/layer-zero-example/test/oappTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const { HEDERA_EID, BSC_EID } = CONSTANTS;
const DATA_FROM_HEDERA = 'dataFromHedera';
const DATA_FROM_BSC = 'dataFromBsc';

Expand Down
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/oftAdapterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;
const amount = '100000000000000000';

describe('OFTAdapterTests', function() {
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('OFTAdapterTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -93,7 +92,7 @@ describe('OFTAdapterTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -119,7 +118,7 @@ describe('OFTAdapterTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.ERC20_HEDERA_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) oft adapter balance: ${await contractERC20.balanceOf(process.env.OFT_ADAPTER_HEDERA_CONTRACT)}`);
Expand All @@ -132,7 +131,7 @@ describe('OFTAdapterTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.ERC20_BSC_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) oft adapter balance: ${await contractERC20.balanceOf(process.env.OFT_ADAPTER_BSC_CONTRACT)}`);
Expand Down
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/oftTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;
const amount = '100000000000000000';

describe('OFTTests', function() {
Expand All @@ -34,7 +33,7 @@ describe('OFTTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -61,7 +60,7 @@ describe('OFTTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -87,7 +86,7 @@ describe('OFTTests', function() {
const signers = await ethers.getSigners();

const contract = await ethers.getContractAt('ExampleOFT', process.env.OFT_HEDERA_CONTRACT);
const receiverBalance = await contract.balanceOf(receiverAddress);
const receiverBalance = await contract.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) receiver balance: ${receiverBalance}`);
Expand All @@ -99,7 +98,7 @@ describe('OFTTests', function() {
const signers = await ethers.getSigners();

const contract = await ethers.getContractAt('ExampleOFT', process.env.OFT_BSC_CONTRACT);
const receiverBalance = await contract.balanceOf(receiverAddress);
const receiverBalance = await contract.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) receiver balance: ${receiverBalance}`);
Expand Down
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/onftAdapterTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;

describe('ONFTAdapterTests', function() {
it('@hedera @mint', async () => {
Expand Down Expand Up @@ -79,7 +78,7 @@ describe('ONFTAdapterTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
tokenId: 1,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
composeMsg: ethers.utils.arrayify('0x'),
Expand All @@ -105,7 +104,7 @@ describe('ONFTAdapterTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
tokenId: 2,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
composeMsg: ethers.utils.arrayify('0x'),
Expand All @@ -129,12 +128,12 @@ describe('ONFTAdapterTests', function() {
it('@hedera @test get owner', async () => {
const contract = await ethers.getContractAt('ERC721Mock', process.env.ERC721_HEDERA_CONTRACT);
const owner = await contract.ownerOf(2);
expect(owner).to.equal(receiverAddress);
expect(owner).to.equal(RECEIVER_ADDRESS);
});

it('@bsc @test get owner', async () => {
const contract = await ethers.getContractAt('ERC721Mock', process.env.ERC721_BSC_CONTRACT);
const owner = await contract.ownerOf(1);
expect(owner).to.equal(receiverAddress);
expect(owner).to.equal(RECEIVER_ADDRESS);
});
});
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/onftTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;

describe('ONFTTests', function() {
it('@hedera @send to bsc', async () => {
const signers = await ethers.getSigners();

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
tokenId: 1,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
composeMsg: ethers.utils.arrayify('0x'),
Expand All @@ -59,7 +58,7 @@ describe('ONFTTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
tokenId: 2,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
composeMsg: ethers.utils.arrayify('0x'),
Expand All @@ -83,12 +82,12 @@ describe('ONFTTests', function() {
it('@hedera @test get owner', async () => {
const contract = await ethers.getContractAt('ExampleONFT', process.env.ONFT_HEDERA_CONTRACT);
const owner = await contract.ownerOf(2);
expect(owner).to.equal(receiverAddress);
expect(owner).to.equal(RECEIVER_ADDRESS);
});

it('@bsc @test get owner', async () => {
const contract = await ethers.getContractAt('ExampleONFT', process.env.ONFT_BSC_CONTRACT);
const owner = await contract.ownerOf(1);
expect(owner).to.equal(receiverAddress);
expect(owner).to.equal(RECEIVER_ADDRESS);
});
});
13 changes: 6 additions & 7 deletions tools/layer-zero-example/test/whbarTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const hre = require('hardhat');
const { ethers } = hre;
const { Options, addressToBytes32 } = require('@layerzerolabs/lz-v2-utilities');
const { expect } = require('chai');
const CONSTANTS = require('./constants');

const HEDERA_EID = 40285;
const BSC_EID = 40102;
const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const { HEDERA_EID, BSC_EID, RECEIVER_ADDRESS } = CONSTANTS;
const amount = '50000000';

describe('WHBARTests', function() {
Expand Down Expand Up @@ -79,7 +78,7 @@ describe('WHBARTests', function() {

const sendParam = {
dstEid: BSC_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -106,7 +105,7 @@ describe('WHBARTests', function() {

const sendParam = {
dstEid: HEDERA_EID,
to: addressToBytes32(receiverAddress),
to: addressToBytes32(RECEIVER_ADDRESS),
amountLD: amount,
minAmountLD: amount,
extraOptions: Options.newOptions().addExecutorLzReceiveOption(3000000, 0).toBytes(),
Expand All @@ -132,7 +131,7 @@ describe('WHBARTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.WHBAR_HEDERA_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) adapter balance: ${await contractERC20.balanceOf(process.env.WHBAR_HEDERA_ADAPTER_CONTRACT)}`);
Expand All @@ -145,7 +144,7 @@ describe('WHBARTests', function() {
const signers = await ethers.getSigners();

const contractERC20 = await ethers.getContractAt('ERC20Mock', process.env.WHBAR_BSC_CONTRACT);
const receiverBalance = await contractERC20.balanceOf(receiverAddress);
const receiverBalance = await contractERC20.balanceOf(RECEIVER_ADDRESS);

console.log(`(${hre.network.name}) signer balance: ${await contractERC20.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) adapter balance: ${await contractERC20.balanceOf(process.env.WHBAR_BSC_ADAPTER_CONTRACT)}`);
Expand Down

0 comments on commit bc38bcd

Please sign in to comment.