Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

nonce errors on any exception #33

Closed
barkthins opened this issue Mar 15, 2016 · 3 comments
Closed

nonce errors on any exception #33

barkthins opened this issue Mar 15, 2016 · 3 comments

Comments

@barkthins
Copy link

If there's any exception such as insufficient gas, subsequent transactions fail with a bad nonce, even though I properly catch the exception in the code.

Error: the tx doesn't have the correct nonce. account has nonce of: 8 tx has nonce of: 7

Below is a patch to ethereum-pudding's test code to show the problem:

This is not reproducible using geth. Simulation != real world issue.

diff --git a/test/contracts.js b/test/contracts.js
index 76e430a..9e2d0e9 100644
--- a/test/contracts.js
+++ b/test/contracts.js
@@ -18,6 +18,7 @@ var binary = compiled.bytecode;
 // Setup
 var web3 = new Web3();
 web3.setProvider(TestRPC.provider());
+//web3.setProvider(new web3.providers.HttpProvider("http://localhost:8110"));
 Pudding.setWeb3(web3);

 var tests = function(contract_instantiator) {
@@ -109,6 +110,7 @@ var tests = function(contract_instantiator) {
       // BigNumber passed in a transaction.
       return example.setValue(new Pudding.BigNumber(25));
     }).then(function(tx) {
+      console.log(tx);
       return example.value.call();
     }).then(function(value) {
       assert.equal(value.valueOf(), 25, "Ending value should be twenty-five");
@@ -118,10 +120,31 @@ var tests = function(contract_instantiator) {
       assert.equal(parrot_value.valueOf(), 865, "Parrotted value should equal 865")
     }).then(done).catch(done);
   });
+
+  it("should throw when running out of gas", function(done) {
+    var example;
+    Example.new().then(function(instance) {
+      example = instance;
+      return example.value.call();
+    }).then(function(value) {
+      assert.equal(value.valueOf(), 1, "Starting value should be 1");
+      return example.setValue(5, {gas: 20000});
+    }).then(function(tx) {
+      return example.value.call();
+    }).then(function(value) {
+      assert.equal(value.valueOf(), 5, "Ending value should be five");
+    }).then(done).catch(function(err) {
+      console.log("properly caught out of gas error");
+      console.log(err);
+      done();
+    });
+  });
 };

 describe("Contract abstractions", function() {

+  this.timeout(40000);  // enough for stock real node e.g. geth
+
   describe("when using .whisk()", function() {
     tests(function(callback) {
       callback(null, Pudding.whisk({

@barkthins
Copy link
Author

BTW Geth had a similar issue 6 months back and fixed it:

ethereum/go-ethereum#1817

@kumavis
Copy link
Contributor

kumavis commented Mar 15, 2016

This should be resolved in provider-engine 7.0.0
MetaMask/web3-provider-engine#45

@barkthins
Copy link
Author

Yes, updating to the latest of ethereumjs-testrpc resolved the issue. Sorry I didn't check version numbers first.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants