6

Honestly, any CI service will do the only requirements are a test blockchain (easy to install ganache-cli ) or use the docker image and other packages of interest including solidity-coverage, eth-gas-reporter, solhint and possibly automatically solidity documentation through solidity-docgen. Although, it took a while to figure out how to use solidity-docgen ...


5

Truffle tests run ganache-cli behind the scene in default mode (10 accounts). But if you run yourself ganache-cli with x accounts generated, you will have access to all of these accounts from your Truffle test. Run Ganache-cli $ ganache-cli -a 15 Ganache CLI v6.1.0 (ganache-core: 2.1.0) Available Accounts ================== (0) ...


4

it("report correctly the best seller"), async () => { let bestSeller = await instance.bestSeller.call(); } // guess you didn't have ')' here, cause if it were there, it does not run to it("report correctly the best seller", async () => { let bestSeller = await instance.bestSeller.call(); }) Watch out for the parenthesis!


4

You get an out of gas because your Conversation[] userConversations; that you believe is in memory is actually on storage. Try to change it to Conversation[] memory userConversations; and you will see that it no longer compiles because .push is not available on memory arrays. How about you try that: function getConversations() public view returns (...


3

If you are implementing the test using truffle framework, then truffle transactions return an object that contains gasUsed property: const txnReceipt = await instance.someFunc(someParam); const gasUsed = txnReceipt.receipt.gasUsed; If you use Ganache as the local test node, you can specify gas price there. Set it as one, and then your eth used is gasUsed*1 ...


3

The values you're showing are 32 bytes long (256 bits), not 64 bits. They're that length because the type is bytes32. The number 1 is different from 10, and the same holds in hexadecimal. You can't just drop the trailing zeros without changing the value. Assuming you're always working with strings, you could use web3.toAscii... e.g. assert.toEqual(web3....


3

To assert the balance of an account, try this: let expectedBalance = web3.toBigNumber(web3.toWei(3, 'ether')); let actualBalance = web3.eth.getBalance(accounts[1]); assert.deepEqual(actualBalance, expectedBalance, "Balance incorrect!");


3

The difference is that Truffle injects Web3.js 0.20 into the test script, whereas you are working with Web3.js 1.0. Web3.js is a whole lot different from Web3.js 0.20.


3

Does truffle test have to begin with a migration process? i.e., I can not skip the migration process and created new contract in test script only? Yes, you can. In your 2_migrate_contracts.js script, change this: module.exports = function(deployer) { deployer.deploy(Register, "tesst", 0); }; To this: module.exports = function(deployer, network, ...


3

This is because ganache has implemented a workaround to forward the reason of a failed require but other clients will fail with a regular exception. This is good for ganache because truffle is able to show the exact cause of an require failure. But the feature is not portable because other clients didn't implement a similar feature.


2

It isn't very clear here what you are trying to achieve. It seems you try to refund token or ether that hasn't been transfered yet ? But, here is a few notes about your code: i. If you transfer ether, you don't need to specify the amount as function argument. But you need to add the keyword payable and transfer the value like that: instChain.isValidBuyer(...


2

This is currently unsupported - see issue https://github.com/trufflesuite/truffle-debugger/issues/32


2

Mixing promises and async/await can create some problems if you are not very careful. I think your test finishes while the call is still running. To ensure the call completes before the test ends try waiting for the result: it("(0,'a'): Should return the StringEmpty code", async () => { const viewResultCode = await instance.validateRow.call(0,'a'); ...


2

Short Answer: Both contracts are creating new instances of Whitelist. They are not sharing the same instance. To share the same instance - they both need to reference the same address of a single deployed Whitelist. By deploying both contracts you are, in fact, wasting (however small or large) gas as both contracts have redundant code. My suggestion (...


2

You Should try to import as:- import { A } from "../contracts/A.sol"; And use A.functionName(). Because in solidity "library" are special type of contracts that specially use to program a reusable piece of code. You can think of this as static function in any OOP language. May this will help you.


2

Before you can run any test, one has to define the starting point, the starting conditions in the smart contract. - Think about the values of the variable in the smart contracts. These conditions are defined by the deployment process. Hence, usually one would first run the deployment before testing. Also, this allows resetting the blockchain easily after ...


2

I actually don't know how your code can compile, this is obviously an issue uint256 expected = "revert overflow error"; and also the errorsEqual method of the assert library is expecting two error codes Anyway one way of going around this would be trying to make a raw call in order to test if there's a revert status inside the VM. The call method will ...


2

Which version of solidity compiler are you using ? I can't reproduce your error. However with last version of solc (0.4.24) you have to add the memory keyword as by default a bytes32[] is stored in storage and you cannot assign a dynamic size type to storage. bytes32[] memory result = simpleStorage.getAllItems();


2

A mocha reporter for Truffle: https://www.npmjs.com/package/eth-gas-reporter Install npm install --save-dev eth-gas-reporter Truffle config module.exports = { networks: { ...etc... }, mocha: { reporter: 'eth-gas-reporter', reporterOptions : { currency: 'CHF', gasPrice: 21 } } };


2

How can I access the value in c? the number is not only what is contained inside c but the whole BigNumber notation, which is accessible with a f.toString() How can I save object f to a javascript variable? f.toString() will give you a string, which can be saved into a variable. Same as you can keep it inside the BigNumber object and use the .toString ...


2

It took me some time to figure out what's wrong with you code (Thanks for the riddle). Here's how i get your test working : 1- I've change truffle.js to following : networks: { local: { host: 'localhost', port: 7545, // gas: 6000010, // gasPrice:10000000000, network_id: '*' } } but instead out of gas i've got revert ...


2

Ah, I got it. It's a Javascript error. It's because I am overwriting the OPCToken that I am importing, here: const OPCToken = await OPCToken.deployed(); It works if I do this instead: const opcToken = await OPCToken.deployed(); I am still a little confused as to why though - doesn't the right hand side evaluate first (at which point it's not been ...


2

You can only send transactions from an account your node (ganache, in this case) knows the private key for. In this code: const transferFrom = await _HouseNFTRegistry.transferFrom( houseOwner, _spvHoldingCrowdsale.address, 1, { from: _spvHoldingCrowdsale.address, to: _HouseNFTRegistry.address } ); you're trying to send a transaction from ...


2

The part about gas amount is simply a "best guess". The system is trying to figure out why it fails but it actually doesn't have any idea. The first part of the error message is more helpful: it fails to store the contract code because it fails to execute the constructor. It's not uncommon around Ethereum to have misleading error messages. Currently it's ...


2

The signature of the toWei method is (can be found in the docs. web3.utils.toWei(number [, unit]) number - String|BN: The value. unit - String (optional, defaults to "ether"): The ether to convert from. So you should provide the number as either a String or a BigNumber (Web3 0.2x) / BN (Web3 1.x). Your code should then be: let result = await instance....


2

You have to return the promise: ... it('My Test', function () { return MyContract.deployed()... }); ... Alternatively, you can use async functions: ... it('My Test', async function () { var myContract = await MyContract.deployed(); console.log(myContract.address); ... }) ...


2

Upon running truffle migrate your contract will not set anything to initial supply. It has no constructor. Upon close inspection I found that you have a function function LearnToken (uint256 _initialSupply) public payable{ balanceOf[msg.sender] = _initialSupply; totalSupply = _initialSupply; } Are you trying to make it your constructor? The ...


2

You can simply use 0, or 0x0000000000000000000000000000000000000000. address(0) in Solidity is equivalent to 0x0000000000000000000000000000000000000000.


2

With Truffle 4.1.15 & Ganache 6.2.5, you can use this: web3.currentProvider.send({method: "evm_increaseTime", params: [120]}); Note that: Between Truffle v4 and Truffle v5, Web3 has changed from v0 to v1, so the above might be different on Truffle 5.x (for example, I think you need to await for the function to complete). Method evm_increaseTime is 1 ...


2

That's a Node question, not a Truffle question, but you can do this in two steps: Step 1 - create file common.js and initialize your common stuff in it, for example: module.exports.myVal = 42; module.exports.myFunc = function(x) {return x;}; Step 2 - import and use this file in your Truffle tests, for example: const common = require("./common.js"); ...


Only top voted, non community-wiki answers of a minimum length are eligible