This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
19 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |