Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Test refactor: call.js (#328)
Browse files Browse the repository at this point in the history
* Refactored call.js #307
  • Loading branch information
ccowell authored and davidmurdoch committed Mar 8, 2019
1 parent e272001 commit 93d5122
Showing 1 changed file with 19 additions and 48 deletions.
67 changes: 19 additions & 48 deletions test/call.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
var Web3 = require("web3");
var assert = require("assert");
var Ganache = require(process.env.TEST_BUILD
? "../build/ganache.core." + process.env.TEST_BUILD + ".js"
: "../index.js");
var fs = require("fs");
var path = require("path");
var solc = require("solc");
const toBytesHexString = require("./helpers/utils/toBytesHexString");
const assert = require("assert");
const bootstrap = require("./helpers/contract/bootstrap");

describe("eth_call", function() {
var web3 = new Web3(Ganache.provider({}));
var accounts;
var estimateGasContractData;
var estimateGasContractAbi;
var EstimateGasContract;
var estimateGasInstance;
var source = fs.readFileSync(path.join(__dirname, "contracts", "gas", "EstimateGas.sol"), "utf8");
let context;

before("get accounts", function(done) {
web3.eth.getAccounts(function(err, accs) {
if (err) {
return done(err);
}
accounts = accs;
done();
});
});

before("compile source and deploy", function() {
before("Setting up web3 and contract", async function() {
this.timeout(10000);
var result = solc.compile({ sources: { "EstimateGas.sol": source } }, 1);

estimateGasContractData = "0x" + result.contracts["EstimateGas.sol:EstimateGas"].bytecode;
estimateGasContractAbi = JSON.parse(result.contracts["EstimateGas.sol:EstimateGas"].interface);
const contractRef = {
contractFiles: ["EstimateGas"],
contractSubdirectory: "gas"
};

EstimateGasContract = new web3.eth.Contract(estimateGasContractAbi);
return EstimateGasContract.deploy({ data: estimateGasContractData })
.send({ from: accounts[0], gas: 3141592 })
.then(function(instance) {
// TODO: ugly workaround - not sure why this is necessary.
if (!instance._requestManager.provider) {
instance._requestManager.setProvider(web3.eth._provider);
}
estimateGasInstance = instance;
});
context = await bootstrap(contractRef);
});

it("should use the block gas limit if no gas limit is specified", function() {
it("should use the block gas limit if no gas limit is specified", async function() {
const { accounts, instance } = context;

const name = "0x54696d"; // Byte code for "Tim"
const description = "0x4120677265617420677579"; // Byte code for "A great guy"
const value = 5;

// this call uses more than the default transaction gas limit and will
// therefore fail if the block gas limit isn't used for calls
return estimateGasInstance.methods
.add(toBytesHexString("Tim"), toBytesHexString("A great guy"), 5)
.call({ from: accounts[0] })
.then((result) => {
assert.strictEqual(result, true);
});
const status = await instance.methods.add(name, description, value).call({ from: accounts[0] });

assert.strictEqual(status, true);
});
});

0 comments on commit 93d5122

Please sign in to comment.