Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 26 characters in body
Source Link
takeshi
  • 1.8k
  • 1
  • 14
  • 33

Testing this function:

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

My truffle test:

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

});

When running testrpc --g 1

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

When running testrpc --g 100000000000

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

Why doesn't gas price influence the amount user_6 receives?

Testing this function:

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

My truffle test:

it("Should let correct payouts and withdrawals", function(done) {
var my_contract = My15.deployed();
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);

});

When running testrpc --g 1

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

When running testrpc --g 100000000000

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

Why doesn't gas price influence the amount user_6 receives?

Testing this function:

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

My truffle test:

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

});

When running testrpc --g 1

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

When running testrpc --g 100000000000

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

Why doesn't gas price influence the amount user_6 receives?

Source Link
takeshi
  • 1.8k
  • 1
  • 14
  • 33

Setting up gasPrice in testrpc doesn't influence the transaction cost

Testing this function:

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

My truffle test:

it("Should let correct payouts and withdrawals", function(done) {
var my_contract = My15.deployed();
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);

});

When running testrpc --g 1

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

When running testrpc --g 100000000000

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

Why doesn't gas price influence the amount user_6 receives?