Skip to content

Commit

Permalink
Merge pull request #16 from sc0Vu/fix-15
Browse files Browse the repository at this point in the history
Fix #15
  • Loading branch information
sc0Vu committed Jun 18, 2018
2 parents 9b5340c + 0f56c03 commit b7714ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = '';
}
Expand Down
32 changes: 32 additions & 0 deletions test/unit/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<count($nonces); $i++) {
$transaction = new Transaction([
'nonce' => $nonces[$i],
'to' => '0x3535353535353535353535353535353535353535',
'gas' => '0x5208',
'gasPrice' => '0x4a817c800',
'value' => '0x0',
'chainId' => 1,
'data' => ''
]);
$signedTransactions[] = $transaction->sign('0x4646464646464646464646464646464646464646464646464646464646464646');
}

// compare each signed transaction
for ($i=1; $i<count($signedTransactions); $i++) {
$this->assertEquals($signedTransactions[0], $signedTransactions[$i]);
}
}
}

0 comments on commit b7714ce

Please sign in to comment.