Skip to content

Commit

Permalink
Fix console.log unsigned int print.
Browse files Browse the repository at this point in the history
Fixes #1182.
  • Loading branch information
scnale committed Jan 30, 2021
1 parent 6cbdaf8 commit 3b4436b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bufferToHex, bufferToInt, fromSigned } from "ethereumjs-util";
import { BN, bufferToHex, bufferToInt, fromSigned } from "ethereumjs-util";
import util from "util";

import {
Expand Down Expand Up @@ -130,6 +130,10 @@ export class ConsoleLogger {
const position = i * 32;
switch (types[i]) {
case UintTy:
return new BN(
data.slice(position, position + REGISTER_SIZE)
).toString(10);

case IntTy:
return fromSigned(
data.slice(position, position + REGISTER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.5.0;

import "./../../../../../../../../console.sol";

contract C {

function log(
uint256 p0, uint256 p1, int256 p2, int256 p3
) public {
console.log(p0);
console.log(p1);
console.logInt(p2);
console.logInt(p3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"description": "Should correctly interpret sign of integer types",
"transactions": [
{
"file": "c.sol",
"contract": "C",
"imports": ["/../../../../../../../../../console.sol"]
},
{
"to": 0,
"function": "log",
"params": [
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000",
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000"
],
"consoleLogs": [
["115792089237316195423570985008687907853269984665640564039457584007913129639935"],
["57896044618658097711785492504343953926634992332820282019728792003956564819968"],
["-1"],
["-57896044618658097711785492504343953926634992332820282019728792003956564819968"]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.6.0;

import "./../../../../../../../../console.sol";

contract C {

function log(
uint256 p0, uint256 p1, int256 p2, int256 p3
) public {
console.log(p0);
console.log(p1);
console.logInt(p2);
console.logInt(p3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"description": "Should correctly interpret sign of integer types",
"transactions": [
{
"file": "c.sol",
"contract": "C",
"imports": ["/../../../../../../../../../console.sol"]
},
{
"to": 0,
"function": "log",
"params": [
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000",
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000"
],
"consoleLogs": [
["115792089237316195423570985008687907853269984665640564039457584007913129639935"],
["57896044618658097711785492504343953926634992332820282019728792003956564819968"],
["-1"],
["-57896044618658097711785492504343953926634992332820282019728792003956564819968"]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.7.0;

import "./../../../../../../../../console.sol";

contract C {

function log(
uint256 p0, uint256 p1, int256 p2, int256 p3
) public {
console.log(p0);
console.log(p1);
console.logInt(p2);
console.logInt(p3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"description": "Should correctly interpret sign of integer types",
"transactions": [
{
"file": "c.sol",
"contract": "C",
"imports": ["/../../../../../../../../../console.sol"]
},
{
"to": 0,
"function": "log",
"params": [
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000",
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x8000000000000000000000000000000000000000000000000000000000000000"
],
"consoleLogs": [
["115792089237316195423570985008687907853269984665640564039457584007913129639935"],
["57896044618658097711785492504343953926634992332820282019728792003956564819968"],
["-1"],
["-57896044618658097711785492504343953926634992332820282019728792003956564819968"]
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,7 @@ async function runTest(

const txIndexToContract: Map<number, DeployedContract> = new Map();

for (
let txIndex = 0;
txIndex < testDefinition.transactions.length;
txIndex++
) {
const tx = testDefinition.transactions[txIndex];

for (const [txIndex, tx] of testDefinition.transactions.entries()) {
let trace: MessageTrace;

if ("file" in tx) {
Expand Down

0 comments on commit 3b4436b

Please sign in to comment.