Skip to content

Commit

Permalink
通过银关存入erc20代币测试不成功,gas有问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jyj545 committed Dec 12, 2019
1 parent 58add66 commit 235f585
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ERC20 extends SmartContract {
try {
const bnBalance = await super.callABI("balanceOf", address);
const decimals = await this.decimals();
balance = bnBalance.dividedBy(10 ** decimals).toString(10);
balance = new BigNumber(bnBalance).dividedBy(10 ** decimals).toString(10);
} catch (error) {
balance = "0";
}
Expand Down
40 changes: 20 additions & 20 deletions test/erc20.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const sandbox = sinon.createSandbox();
const config = require("./config");
const Contract = require("web3-eth-contract");

describe('test EtherFingate', function() {
describe('test constructor', function() {
it("create successfully", function() {
describe('test EtherFingate', function () {
describe('test constructor', function () {
it("create successfully", function () {
let inst = new ERC20();
const ethereum = new Ethereum(config.MOCK_NODE, true);
ethereum.initWeb3();
Expand All @@ -23,7 +23,7 @@ describe('test EtherFingate', function() {
expect(inst._ethereum).to.deep.equal(ethereum);
sandbox.restore();
});
it('throws error if init error', function() {
it('throws error if init error', function () {
let inst = new ERC20();
const ethereum = new Ethereum(config.MOCK_NODE, true);
ethereum.initWeb3();
Expand All @@ -33,7 +33,7 @@ describe('test EtherFingate', function() {
})
})

it("destroy and destroyWeb3 should be called once", function() {
it("destroy and destroyWeb3 should be called once", function () {
let inst = new ERC20();
const ethereum = new Ethereum(config.MOCK_NODE, true);
ethereum.initWeb3();
Expand All @@ -42,7 +42,7 @@ describe('test EtherFingate', function() {
expect(inst._contract).to.equal(null);
})

describe("test balanceOf", function() {
describe("test balanceOf", function () {
let inst;
before(() => {
inst = new ERC20();
Expand All @@ -55,10 +55,10 @@ describe('test EtherFingate', function() {
sandbox.restore();
})

it("return 1 if resolve 1000000000000000000", async function() {
it("return 1 if resolve 1000000000000000000", async function () {
const s1 = sandbox.stub(inst._contract.methods, "balanceOf");
s1.returns({
call: function() {
call: function () {
return new Promise((resolve, reject) => {
resolve("1000000000000000000")
})
Expand All @@ -68,7 +68,7 @@ describe('test EtherFingate', function() {
s2.resolves();
const s3 = sandbox.stub(inst._contract.methods, "decimals");
s3.returns({
call: function() {
call: function () {
return new Promise((resolve, reject) => {
resolve("18")
})
Expand All @@ -77,13 +77,13 @@ describe('test EtherFingate', function() {
const s4 = sandbox.stub(s3, "call");
s4.resolves();
const balance = await inst.balanceOf(config.ETHEREUM_ADDRESS);
expect(balance).to.equal("0");
expect(balance).to.equal("1");
})

it("return 0 if request failed", async function() {
it("return 0 if request failed", async function () {
const s1 = sandbox.stub(inst._contract.methods, "balanceOf");
s1.returns({
call: function() {
call: function () {
return new Promise((resolve, reject) => {
reject(new Error("network error"))
})
Expand All @@ -96,9 +96,9 @@ describe('test EtherFingate', function() {
})
})

describe("test transfer", function() {
describe("test transfer", function () {
let inst;
before(function() {
before(function () {
inst = new ERC20();
const ethereum = new Ethereum(config.MOCK_NODE, true);
ethereum.initWeb3();
Expand All @@ -113,26 +113,26 @@ describe('test EtherFingate', function() {
expect(() => inst.transfer(config.ETHEREUM_SECRET, config.SC_ADDRESS, "-1")).throw(`-1 is invalid amount.`)
})

it('moac secret is invalid', function() {
it('moac secret is invalid', function () {
expect(() => inst.transfer(config.ETHEREUM_SECRET.substring(1), config.SC_ADDRESS, 1)).throw(`${config.ETHEREUM_SECRET.substring(1)} is invalid ethereum secret.`)
})

it('destination address is invalid', function() {
it('destination address is invalid', function () {
expect(() => inst.transfer(config.ETHEREUM_SECRET, config.SC_ADDRESS.substring(1), 1)).throw(`${config.SC_ADDRESS.substring(1)} is invalid ethereum address.`)
})

it('reject error', async function() {
it('reject error', async function () {
try {
await inst.transfer(config.ETHEREUM_SECRET, config.JC_CONTRACT, 1);
} catch (error) {
expect(error).to.be.an("error");
}
})

it("transfer success", async function() {
it("transfer success", async function () {
const s2 = sandbox.stub(inst._contract.methods, "decimals");
s2.returns({
call: function() {
call: function () {
return new Promise((resolve, reject) => {
resolve("18")
})
Expand All @@ -142,7 +142,7 @@ describe('test EtherFingate', function() {
s3.resolves();
const s1 = sandbox.stub(inst._contract.methods, "transfer");
s1.returns({
encodeABI: function() {
encodeABI: function () {
return "0xa9059cbb0000000000000000000000003907acb4c1818adf72d965c08e0a79af16e7ffb8000000000000000000000000000000000000000000000000016345785d8a0000"
}
})
Expand Down

0 comments on commit 235f585

Please sign in to comment.