I use Truffle to develop locally and run tests with truffle test
(letting it create a temporary local blockchain).
In one of my tests I need to sign a message and for that I need the test wallet's privateKey
. Unfortunately Truffle's contract()
provides only an array of accounts
(an array of addresses). I googled and it seems that there is no way to get the private key for those addresses.
So I tried the following:
await web3.eth.accounts.wallet.create(1);
const wallet = web3.eth.accounts.wallet[0];
// ok
const signedMessage = await wallet.sign('message');
// 🆘 fails with "sender account not recognized"
const contract = await MyContract.new({ from: wallet.address });
The Issue: The message signer should also be the deployer of the contract but when I try to instantiate the contract as the newly created wallet.address
I get the following error:
1) Contract: MyContract
test case no. 1 :
Error: Returned error: sender account not recognized
at Context.<anonymous> (test/my_contract.js:67:43)
at processTicksAndRejections (node:internal/process/task_queues:96:5)