Skip to content

Commit

Permalink
finish some test
Browse files Browse the repository at this point in the history
  • Loading branch information
moyaying committed Mar 4, 2021
1 parent c4185c4 commit 4b3990a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 57 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# hyn-bridge
run external scipts
```
truffle exec script/demo.js --network hecotest
```
101 changes: 56 additions & 45 deletions migrations/2_deploy_heco_contracts.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
const ERC20HecoManager = artifacts.require("ERC20HecoManager");
const TokenManager = artifacts.require("TokenManager");
const BridgedToken = artifacts.require("BridgedToken");

// roles:
// 1. admin: deploy TokenManager,
// 2. heco
// a. master: deploy hecoManager
// b. hecoUser:
// 3. atlas
// a. master: deploy atlasManager
// b. atlasUser:
module.exports = function (deployer, network, accounts) {
let rpTokenAddress = '0x562D6AFA2A0aD94c8B2946e23C96E27F3cD023e8'
if(network == 'heco') {
rpTokenAddress = '0x88880126bC73107118f18000309d10dB9f1d6a14'
}
const HYN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
let tokenManager, hecoManager;
deployer.then(async () => {
// if(network == 'hecotest') {
//
// }
await deployer.deploy(TokenManager);
tokenManager = await TokenManager.deployed()
let rpTokenAddress = '0x562D6AFA2A0aD94c8B2946e23C96E27F3cD023e8'
if (network == 'heco') {
rpTokenAddress = '0x88880126bC73107118f18000309d10dB9f1d6a14'
}
const HYN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
let tokenManager, hecoManager;
deployer.then(async () => {
// if(network == 'hecotest') {
// }
tokenManager = await deployer.deploy(TokenManager);
hecoManager = await deployer.deploy(ERC20HecoManager);

await deployer.deploy(ERC20HecoManager);
hecoManager = await ERC20HecoManager.deployed()
// rely
console.log('begin rely', hecoManager.address)
await tokenManager.rely(hecoManager.address)
// await tokenManager.rely(accounts[0])
console.log('rely done')

// rely
await tokenManager.rely(hecoManager.address)
//add hyn token
const hynName = 'Hyperion Token';
const hynSymbol = 'HYN';
const hynDecimals = 18;
let hecoHynTokenAddr = await tokenManager.mappedTokens(HYN_ADDRESS)
if (hecoHynTokenAddr == '0x0000000000000000000000000000000000000000') {
// console.log('deploy BridgedToken', HYN_ADDRESS, hynName, hynSymbol, hynDecimals)
// let hecoHynToken = await deployer.deploy(BridgedToken, HYN_ADDRESS, hynName, hynSymbol, hynDecimals)
// console.log('add minter', hecoManager.address)
// await hecoHynToken.addMinter(hecoManager.address)
// console.log('registerToken', HYN_ADDRESS, hecoHynToken.address)
// await tokenManager.registerToken(HYN_ADDRESS, hecoHynToken.address)

//add hyn token
const hynName = 'Hyperion Token';
const hynSymbol = 'HYN';
const hynDecimals = 18;
let hecoHynTokenAddr = await tokenManager.mappedTokens(HYN_ADDRESS)
if(hecoHynTokenAddr == '0x0000000000000000000000000000000000000000') {
await hecoManager.addToken(tokenManager.address, HYN_ADDRESS, hynName, hynSymbol, hynDecimals)
hecoHynTokenAddr = await tokenManager.mappedTokens(HYN_ADDRESS)
}
console.log('hecoHynTokenAddr', hecoHynTokenAddr)
console.log('begin addHynToken', tokenManager.address, HYN_ADDRESS, hynName, hynSymbol, hynDecimals)
await hecoManager.addToken(tokenManager.address, HYN_ADDRESS, hynName, hynSymbol, hynDecimals)
hecoHynTokenAddr = await tokenManager.mappedTokens(HYN_ADDRESS)
console.log('addHynToken done', hecoHynTokenAddr)
}
console.log('hecoHynTokenAddr', hecoHynTokenAddr)

// add rp token
const rpName = 'RP Token';
const rpSymbol = 'RP';
const rpDecimals = 18;
let hecoRpTokenAddr = await tokenManager.mappedTokens(rpTokenAddress)
if(hecoRpTokenAddr == '0x0000000000000000000000000000000000000000') {
await hecoManager.addToken(tokenManager.address, rpTokenAddress, rpName, rpSymbol, rpDecimals)
hecoRpTokenAddr = await tokenManager.mappedTokens(rpTokenAddress)
}
console.log('hecoRpTokenAddr', hecoRpTokenAddr)
});
// add rp token
const rpName = 'RP Token';
const rpSymbol = 'RP';
const rpDecimals = 18;
let hecoRpTokenAddr = await tokenManager.mappedTokens(rpTokenAddress)
if (hecoRpTokenAddr == '0x0000000000000000000000000000000000000000') {
// console.log('deploy BridgedToken', rpTokenAddress, rpName, rpSymbol, rpDecimals)
// let hecoRpToken = await deployer.deploy(BridgedToken, rpTokenAddress, rpName, rpSymbol, rpDecimals)
// console.log('add minter', hecoManager.address)
// await hecoRpToken.addMinter(hecoManager.address)
// console.log('registerToken', rpTokenAddress, hecoRpToken.address)
// await tokenManager.registerToken(rpTokenAddress, hecoRpToken.address)

console.log('begin addToken', tokenManager.address, rpTokenAddress, rpName, rpSymbol, rpDecimals)
await hecoManager.addToken(tokenManager.address, rpTokenAddress, rpName, rpSymbol, rpDecimals)

hecoRpTokenAddr = await tokenManager.mappedTokens(rpTokenAddress)
console.log('addRpToken done', hecoRpTokenAddr)
}
console.log('hecoRpTokenAddr', hecoRpTokenAddr)
});
};
54 changes: 54 additions & 0 deletions script/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const ERC20AtlasManager = artifacts.require("ERC20AtlasManager");
const MyERC20 = artifacts.require("MyERC20");
const ERC20HecoManager = artifacts.require("ERC20HecoManager");
const TokenManager = artifacts.require("TokenManager");
const BridgedToken = artifacts.require("BridgedToken");

module.exports = async function (callback) {
let hecoManagerAddr = ''
let tokenAddress = ''
let tokenManagerAddr = ''

const networkType = process.argv[process.argv.length - 1];
if (networkType === 'development') {
hecoManagerAddr = '0x4F39a925CF5781451BA3D640bFd333d7720a7555' // dev address
tokenAddress = '0x55cc4e6d6e13ce403ce617e0240bf4405aa4d972' // dev token address
tokenManagerAddr = '0x419Fd24f4C0044faB8f472EED64619679023b347' //dev
} else if (networkType === 'hecotest') {
hecoManagerAddr = '0xdFc01fE7Bac53B4d72518d5ad0e1131b83628fF3'
tokenAddress = '0x1990f4c2D9cbB7587e1864812d0403e52fa32f03' // heco test token
tokenManagerAddr = '0xf50005d5F49b25CA032F95A56A38B1cB634C69fF' //heco test
}

try {
console.log('xxxx1');

// let abi = web3.eth.abi.encodeParameters(['address','string', 'string', 'uint8'], ['0x562D6AFA2A0aD94c8B2946e23C96E27F3cD023e8', 'RP TOKEN', 'RP', 18]);
// let abi = web3.eth.abi.encodeParameters(['address','string', 'string', 'uint8'], ['0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', 'Hyperion Token', 'HYN', 18]);
// console.log(abi)
// callback();
// return;

let hecoManager = await ERC20HecoManager.at(hecoManagerAddr)

let recipient = '0x9AE56FD9862CbF6188b495D8eE6A45EE261E5306'
let receiptId = '0x6d71a1bfc43e477124663e48de191930630df6c1eb76c6095ea1b86bbb65dbd2'
let mintAmount = web3.utils.toWei('300', 'ether')
console.log('xxxx2');

let token = await BridgedToken.at(tokenAddress)
let tokenBanaceOfRecipient = await token.balanceOf(recipient);
console.log('xxxx3', web3.utils.fromWei(tokenBanaceOfRecipient, 'ether'));

let tx = await hecoManager.mintToken(tokenAddress, mintAmount, recipient, receiptId)
console.log(tx)

tokenBanaceOfRecipient = await token.balanceOf(recipient);
console.log('xxxx3-2', web3.utils.fromWei(tokenBanaceOfRecipient, 'ether'));

console.log('xxxx4');
} catch (e) {
console.error(e)
}
callback();
}
17 changes: 9 additions & 8 deletions test/common_test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const truffleAssert = require('truffle-assertions');

const ERC20AtlasManager = artifacts.require("ERC20AtlasManager");
const MyERC20 = artifacts.require("MyERC20");
const ERC20HecoManager = artifacts.require("ERC20HecoManager");
const TokenManager = artifacts.require("TokenManager");
const BridgedToken = artifacts.require("BridgedToken");

contract('Common Testing', (accounts) => {
beforeEach("Initialize", async () => {
console.log('xxx1-1', await web3.eth.getAccounts())
console.log('xxx1-2', web3.eth.accounts.wallet)
console.log('xxx1-3', web3.utils.toWei('1', 'ether'))
console.log('xxx2', process.env.NETWORK)
});

it("test common", async () => {
console.log('xxx3', process.env.NETWORK)
let token = await BridgedToken.at('0x1990f4c2D9cbB7587e1864812d0403e52fa32f03')
// let tx = await token.mint('0x89A9855032047fAF65BAA95F43128af6EE5721eD', web3.utils.toWei('1', 'ether'))
let name = await token.name();
console.log(name)
});

});
7 changes: 6 additions & 1 deletion test/init_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ let hecoManager;
// for test
let tokenManagerAddress = '0xc6526A3B7E35a1ACDdAA85E5879AD301fa46724e'
let hecoManagerAddress = '0x33bB65f976659AB3b7142812c158aEd404c73611'
let rpTokenAddress = '0x562D6AFA2A0aD94c8B2946e23C96E27F3cD023e8' //0x88880126bC73107118f18000309d10dB9f1d6a14
let rpTokenAddress = '0x562D6AFA2A0aD94c8B2946e23C96E27F3cD023e8'

// mainnet
// let tokenManagerAddress = ''
// let hecoManagerAddress = ''
// let rpTokenAddress = '0x88880126bC73107118f18000309d10dB9f1d6a14'

const HYN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'

Expand Down
7 changes: 4 additions & 3 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ module.exports = {
// options below to some value.
//
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
// host: "127.0.0.1", // Localhost (default: none)
// port: 7545, // Standard Ethereum port (default: none)
provider: () => new HDWalletProvider(process.env.ADMIN_MNENOMIC, "http://127.0.0.1:7545"),
network_id: 5777, // Any network (default: none)
gas: 10000000,
gasPrice: 10000000000
Expand All @@ -52,7 +53,7 @@ module.exports = {
provider: () => new HDWalletProvider(process.env.ADMIN_MNENOMIC, "https://http-testnet.hecochain.com"),
network_id: 256,
gas: 8000000,
gasPrice: 1000000000
gasPrice: 10000000000
},

// mainnet - heco
Expand Down

0 comments on commit 4b3990a

Please sign in to comment.