First of all, sorry for the code in Portuguese, this was a choice of the team and I had no saying on that.
I'm writing a Billet Manager, the code is as follows:
contract GerenciadorBoletos {
struct Boleto {
uint codigoBarra;
uint codigoBarraDigitavel;
uint cpfOuCnpjBeneficiario;
uint cpfOuCnpjPagador;
uint valorOriginal;
uint dataVencimento;
}
mapping(uint => Boleto) registroBoletos;
function inserirBoleto(
uint codigoBarra,
uint codigoBarraDigitavel,
uint cpfOuCnpjBeneficiario,
uint cpfOuCnpjPagador,
uint valorOriginal,
uint dataVencimento
) {
Boleto memory b = Boleto(
codigoBarra,
codigoBarraDigitavel,
cpfOuCnpjBeneficiario,
cpfOuCnpjPagador,
valorOriginal,
dataVencimento
);
// I need to do some validations before store it, but there is no code yet
registroBoletos[b.codigoBarra] = b;
}
}
I'm testing it with TestRPC and Mocha:
describe('1. Inserção', function(){
it('Deve ter inserido um boleto com os dados válidos com sucesso', function(done){
var boletoParaInserir = gerarBoletoValido();
console.log(boletoParaInserir);
gerenciadorBoleto.inserirBoleto.sendTransaction(
9872387128, 987128382, 91289312, 81273818, 50, Date.now() + 3*24*3600,
{
from: web3.eth.accounts[0],
gas: 3000000,
},
function(e, result) {
expect(e).to.not.exist;
expect(result).to.exist;
result.should.be.above(0);
}
);
});
});
I'm getting the following error:
Uncaught AssertionError: expected [Error: Error: VM Exception while executing transaction: invalid opcode
Edit
This seems to be an issue with TestRPC.
I've opened an issue on github.
Best Answer
Summary
There is no error when the code is inserted into
geth
and run.Can you try inserting your code into
geth
and see if you still the geth "invalid opcode" error.From the OPs response in the comment, the "invalid opcode" issue is caused by the timing of the test case.
Details
Modified Your Code
I've modified your code slightly, changing the
//
comment into/* ... */
and added a public to your mapping structure:Running
geth
I'm running the Dev blockchain using the following parameters:
Flattened Your Code And Assigned To A Variable
You can use a service like Line Break Removal Tool to strip out your line breaks, or see How to load Solidity source file into geth for some alternatives.
I flattened your code, assigned it to a variable and pasted it into
geth
:Compiled Your Code
I compiled your code using the following command:
Inserted Your Code Into The Blockchain
I used the following commands to insert your code into the blockchain:
And waited for the following message:
Sent Transaction To Add Data
I copied the main part of your
sendTransaction
to insert your sample data into the blockchain:And waited for the transaction to be mined.
Inspecting Data After Data Inserted
No Invalid Opcode
I double checked my
geth
messages and I did not get the "invalid opcode" message.