La configuración de gasPrice en testrpc no influye en el costo de la transacción

Probando esta función:

function withdrawAll () 
public
stopInEmergency () {
    if (!msg.sender.send(12 finney)) {
        throw;
    }
}

Mi prueba de trufa:

it("Should let correct payouts and withdrawals", function(done) {
var my_contract = My15.deployed();
var unit = "finney";
const user_6_initialBalance = web3.eth.getBalance(user_6);
var  user_6_gas_cost = 0;

return my_contract.withdrawAll ({from: user_6});
    .then(function(tx_id){

        user_6_gas_cost = web3.eth.getTransactionReceipt(tx_id).gasUsed * web3.eth.gasPrice;

        const user_6_finalBalance = web3.eth.getBalance(user_6); 
        const withdrawn = web3.toWei(12, unit);
        const recieved = user_6_finalBalance - user_6_initialBalance;
        const diff = withdrawn - recieved;

        console.log('gasPrice: ', web3.eth.gasPrice.toString(10)); 
        console.log('withdrawn: ', web3.fromWei(withdrawn, unit));
        console.log('recieved: ', web3.fromWei(recieved, unit));
        console.log("gas cost: ", web3.fromWei(user_6_gas_cost, unit));
        console.log('diff: ', web3.fromWei(diff, unit));

    }).then(function(){
        done();
    }).catch(done);

});

Al ejecutar testrpc --g 1

gasPrice:  1
withdrawn:  12
recieved:  9.127600000008192
gas comission:  0.000000000028724
diff:  2.872399999991808

Al ejecutar testrpc --g 100000000000

gasPrice:  100000000000
withdrawn:  12
recieved:  9.127600000008192
gas comission:  2.8724
diff:  2.872399999991808

¿Por qué el precio de la gasolina no influye en la cantidad que recibe user_6?

Supongo var unit = "finney"que falta?
@XavierLeprêtreB9lab ¡Sí, gracias! Actualizada la pregunta.

Respuestas (1)

En su ejemplo, está usando el precio del gas de la red y debe usar el precio del gas de transacción.

user_6_gas_cost = web3.eth.getTransactionReceipt(tx_id).gasUsed *
    web3.eth.getTransaction(tx_id).gasPrice;

Si no configura gasPrice en una transacción, usará un valor predeterminado (con testrpc parece ser 100 Gwei). No utilizará el precio del gas de red (devuelto por web3.eth.gasPrice) . Tienes que fijar explícitamente el precio del gas que quieres.

my_contract.withdrawAll ({ from: user_6, gasPrice: web3.eth.gasPrice })