Skip to content

Commit

Permalink
fix(sc): Fix _emitNum emitting trimmed hex numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
snowypowers committed Feb 10, 2018
1 parent 0004a4a commit bff80dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/sc/ScriptBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class ScriptBuilder extends StringStream {
if (num === -1) return this.emit(OpCode.PUSHM1)
if (num === 0) return this.emit(OpCode.PUSH0)
if (num > 0 && num <= 16) return this.emit(OpCode.PUSH1 - 1 + num)
return this.emitPush(reverseHex(int2hex(num)))
const hexstring = int2hex(num)
return this.emitPush(reverseHex('0'.repeat(16 - hexstring.length) + hexstring))
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/sc/scriptBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ describe('ScriptBuilder', function () {
},
{
int: 500,
result: '02f401' // prefixed with number of bytes following (02)
result: '08f401000000000000'
},
{
int: 65536,
result: '03000001'
result: '080000010000000000'
}
]

Expand Down

0 comments on commit bff80dd

Please sign in to comment.