From 0f56c03186f09255a3dca6b015e7d275d66d84af Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 18 Jun 2018 17:11:31 +0800 Subject: [PATCH] Fix #15 Change * Change nonce, gas, gasLimit, gasPrice allowZero to false. * Change check zero statement. * Add test for issue #15. --- src/Transaction.php | 12 ++++++------ test/unit/TransactionTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Transaction.php b/src/Transaction.php index 3aebe73..0a4ad3e 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -37,25 +37,25 @@ class Transaction implements ArrayAccess 'key' => 0, 'length' => 32, 'allowLess' => true, - 'allowZero' => true + 'allowZero' => false ], 'gasPrice' => [ 'key' => 1, 'length' => 32, 'allowLess' => true, - 'allowZero' => true + 'allowZero' => false ], 'gasLimit' => [ 'key' => 2, 'length' => 32, 'allowLess' => true, - 'allowZero' => true + 'allowZero' => false ], 'gas' => [ 'key' => 2, 'length' => 32, 'allowLess' => true, - 'allowZero' => true + 'allowZero' => false ], 'to' => [ 'key' => 3, @@ -236,8 +236,8 @@ public function offsetSet($offset, $value) } } if (!isset($txKey['allowZero']) || (isset($txKey['allowZero']) && $txKey['allowZero'] === false)) { - // check zero, 0x0 - if ($checkedValue === '0' && ($value === 0 || $value === '0x0' || $value === '0x')){ + // check zero + if (preg_match('/^0*$/', $checkedValue) === 1) { // set value to empty string $value = ''; } diff --git a/test/unit/TransactionTest.php b/test/unit/TransactionTest.php index eb5051a..09ca49c 100644 --- a/test/unit/TransactionTest.php +++ b/test/unit/TransactionTest.php @@ -286,4 +286,36 @@ public function testGetFromAddress() $this->assertEquals($fromA, $fromB); $this->assertEquals($fromB, $fromC); } + + /** + * testIssue15 + * + * @return void + */ + public function testIssue15() + { + $signedTransactions = []; + $nonces = [ + '0x00', '0x0', 0, '0x000', '0' + ]; + + // push signed transaction + for ($i=0; $i $nonces[$i], + 'to' => '0x3535353535353535353535353535353535353535', + 'gas' => '0x5208', + 'gasPrice' => '0x4a817c800', + 'value' => '0x0', + 'chainId' => 1, + 'data' => '' + ]); + $signedTransactions[] = $transaction->sign('0x4646464646464646464646464646464646464646464646464646464646464646'); + } + + // compare each signed transaction + for ($i=1; $iassertEquals($signedTransactions[0], $signedTransactions[$i]); + } + } }