0

I want to test gas limits of the block.

Currently in my tests:

console.log(accounts); console.log(accounts.length);

I have 10 accounts, what to do if I want more?

Related: https://github.com/trufflesuite/truffle/issues/771

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) 0x0db5a29ba9c8ba9828d762361100eee40c27d534
(1) 0x0ee6079af81bde6f26668acb3ebe88da62688746
(2) 0xf7a97a29e36ab303c7427fdbc11e47442fc5e0e6
(3) 0x062e63e393e6fa22cac0952dae11cb95347a3c41
(4) 0xcc10e5fc80ca5245f8e88f07c8f25956166fab97
(5) 0xc251a8a9920544e8c0fbd8aa65857ec1db00f2dd
(6) 0x06022629d7fd960585d3b33f1d53c86a969a2493
(7) 0x962c196fde6998744c69939213d47eee071d6b0a
(8) 0x6ea526f5b81822cbfe166e4fbba2752a42597d04
(9) 0xc11398eff1f1382074790eeb80053e09b15ef4cf
(10) 0x330997e70b83f1a562490fcaa5996314fa5a971a
(11) 0x30af8cdd1bac5ad8ae0e71a15aae563fe046a259
(12) 0x98544babd863f5ce635453728aee5e1e22362782
(13) 0x0751f545185fae1a882c311fcc3e8c00fb206fba
(14) 0xb2ed8ebb091c17c21b4c6cd1ef768b66c31d15bc

Private Keys
==================
(0) 91eb77d7aed3f81a9f981ca9e6fa1228e95cbd41012eb730c6e973ebb62a066f
(1) 051c7b1b210394fa863b760a406d56e69c7724d787a41927ac7f4a1d012b1185
(2) a7f19b34d12427612b25856f1a3f9727c464864ad5f63bba9b305840735bdc92
(3) a9b6f09091b9daa9d7caae2c018b19ab921e98a1106239b2a58a6bd1a4abc943
(4) 69a0315f0a6932ca52d5b1ad9ce31b2fef7de658f8da625a6d97f4dbb3ba22c1
(5) 2c06b48c205efccc3506430212630a11bcc99cad1994452898e5df63985eda10
(6) d890fedd404c6f49daf4be91cd720df22786e1d35d579b8372cc531eed80a267
(7) 9da43e9603043299cd6c5aecec69b7713342496f3465caaadbee5db955f18010
(8) 53a2a4124387132ceae955edb80f13aa549f2e956d3f8aae0383412a3c765a93
(9) 1803ea57835da6f03f8b43458482f65f280600c278947fe0eaf78c5d7d260c81
(10) b13f2706716d269a9639f2eb99d38ba8aaef0e210d1b35a2e40e3e8b62ab76f9
(11) 6ea3ff0add2ecee82d3ba59968d4a62bb7345f908a126a8827f6f1f323b83d42
(12) e5fdc32e5d479f9ad7cbe140cc0f28c89fc6b6d5b9d36f2538fd674348a76ca0
(13) 35236c790a4477e16e90dbd1a6cf34979fbd3ccedb0f02992125a29b22ec50fe
(14) 3866d014b5d0fc7786326fd1eb263ae99a78e415ced643a6c477c0990054f7b4

HD Wallet
==================
Mnemonic:      solar hurry climb pass about loud siren bean close link tower all
Base HD Path:  m/44'/60'/0'/0/{account_index}

Listening on localhost:8545

Execute the tests

$ truffle test
Using network 'development'.

[ '0x0db5a29ba9c8ba9828d762361100eee40c27d534',
  '0x0ee6079af81bde6f26668acb3ebe88da62688746',
  '0xf7a97a29e36ab303c7427fdbc11e47442fc5e0e6',
  '0x062e63e393e6fa22cac0952dae11cb95347a3c41',
  '0xcc10e5fc80ca5245f8e88f07c8f25956166fab97',
  '0xc251a8a9920544e8c0fbd8aa65857ec1db00f2dd',
  '0x06022629d7fd960585d3b33f1d53c86a969a2493',
  '0x962c196fde6998744c69939213d47eee071d6b0a',
  '0x6ea526f5b81822cbfe166e4fbba2752a42597d04',
  '0xc11398eff1f1382074790eeb80053e09b15ef4cf',
  '0x330997e70b83f1a562490fcaa5996314fa5a971a',
  '0x30af8cdd1bac5ad8ae0e71a15aae563fe046a259',
  '0x98544babd863f5ce635453728aee5e1e22362782',
  '0x0751f545185fae1a882c311fcc3e8c00fb206fba',
  '0xb2ed8ebb091c17c21b4c6cd1ef768b66c31d15bc' ]
length: 15

EDIT: Configuration details

$ cat truffle.js 
module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }
};

$ cat test/test.js 
var Contract = artifacts.require("Weechain.sol");

contract('Contract', function(accounts) {
    console.log(accounts);
    console.log("length: " + accounts.length);
});

$ truffle version
Truffle v4.1.5 (core: 4.1.5)
Solidity v0.4.21 (solc-js)

$ ganache-cli version
Ganache CLI v6.1.0 (ganache-core: 2.1.0)
  • -a 15 works nicely... But truffle test gives me Using network 'test'. and still only 10 accounts... Do I need to put any special configuration? truffleframework.com/docs/advanced/configuration – Mars Robertson May 13 '18 at 20:38
  • Just edited my answer with more details about my setup. – Greg Jeanmart May 13 '18 at 20:49
  • Thanks! I was just about to lose some sanity, and then realized I had two files in the repo truffle-config.js (rubbish) and truffle.js (that's the one) – Mars Robertson May 13 '18 at 21:33
0

Here is an example of 15 accounts (the ^ is in order to break the command line into multiple lines in Windows, so replace it with whatever is appropriate on your operating system):

ganache-cli --port=8545 --gasLimit=0xfffffffffff ^
--account=0x0000000000000000000000000000000000000000000000000000000000000001,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000002,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000003,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000004,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000005,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000006,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000007,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000008,1000000000000000000000000000000000000000 ^
--account=0x0000000000000000000000000000000000000000000000000000000000000009,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000A,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000B,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000C,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000D,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000E,1000000000000000000000000000000000000000 ^
--account=0x000000000000000000000000000000000000000000000000000000000000000F,1000000000000000000000000000000000000000 

The first parameter for each account is the account's private key (choose freely).

The second parameter for each account is the account's balance (choose generously).

  • I think that -a 15 is an easier way, see another answer. I also want to know how to convince truffle test to use it... Maybe you'll know? – Mars Robertson May 13 '18 at 20:39
  • @MichalStefanow: Easier, but if you don't setup a large enough balance then you'll get into trouble later on in your tests. If you run truffle on the same port (8545 in this case) then they will "work together". – goodvibration May 14 '18 at 3:22
  • Fair play. Second parameter being a balance, nice! – Mars Robertson May 14 '18 at 15:55
0

I'm using the ganache UI-Version (not the cli one). On the settings page you can configure the amount of accounts you want to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.