7

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 ...


6

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


6

Prior to Solidity v0.4.21: contract ContractName { function ContractName(...) public { ... } ... } Solidity v0.4.21 onward: contract ContractName { constructor(...) public { ... } ... } The reason: In the older version, if you renamed the contract but forgot to rename the constructor, the latter would turn into a ...


5

I ran into this issue as well, and it is indeed the intended behavior of truffle test: cleanroom behavior. Each run of truffle test redeploys the contracts. If it didn't, then saved state from a prior run could affect the results of a subsequent run, making your test suite non-deterministic. But I wanted to preserve state between runs of truffle test. The ...


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) ...


5

There is an issue in a way you use HDWalletProvider when configuring development network in truffle-config.js. You should add it like: provider: () => new HDWalletProvider('your mnemonic', 'http://127.0.0.1:7545') For me, it helped. Additional info can be found here.


5

You can use HDWalletProvider to connect to a provider (infura or your local node) using a mnemonic phrase. In case you are using truffle, you can do it by seting you config to something like this: ... networks: { kovan: { provider: () => new HDWalletProvider(mnemonic, `https://kovan.infura.io/v3/${infuraKey}`), network_id: 3, ...


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 (...


4

Use openzeppelin-test-helpers Specifically use expectEvent.inTransaction I created an example in the community forum for how to use: https://forum.zeppelin.solutions/t/how-to-check-for-events-that-was-dispatched-in-a-nested-operation/955/2


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

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

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 ...


3

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 ...


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.


3

You can't get the return data from transactions. It's not included in the tx receipt, which is why calling enroll() returns the tx object instead of the data. If you want to get the data it returns, you have to do a call instead of a transaction, using await bank.enroll.call({from:alice}). This however wont actually change any state variables of course.


3

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


3

I had the same problem and I managed it as follows: https://github.com/trufflesuite/truffle/issues/2176 So just by manually deleting the build folder and creating it back again just running the test.


3

First you need to know that sha256 and keccak256 functions are not the same. Check the docs to see available functions. sha256 (with pyhton): >>> sha256("Hello World!").hexdigest() '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069' keccak256 (with web3): web3.utils.keccak256("Hello World!") '...


3

Just found out that my test code had wrong brackets placement: it was contract("Marketplace"), accounts => { //all tests go inside here let marketplace; before(async () => { marketplace = await Marketplace.deployed(); }); //describe comes from Mocha framework describe("deployment", async () => { it("deploys successfully", ...


3

Related to how to test overloaded function in truffle?, but slightly different with passing a struct. The solution is simple: MyContract.methods['init((address,address,address))'](myStruct)


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

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

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 ...


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