Merge pull request #3613 from ethereum/scientific_notatioin

allow scientific notation
pull/3621/head
yann300 2 years ago committed by GitHub
commit 5132c5e1a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      apps/remix-ide-e2e/src/tests/transactionExecution.test.ts
  2. 14
      libs/remix-lib/src/execution/txHelper.ts
  3. 1
      package.json
  4. 5
      yarn.lock

@ -134,6 +134,19 @@ module.exports = {
.click('*[data-id="deployAndRunClearInstances"]') .click('*[data-id="deployAndRunClearInstances"]')
}, },
'Should use scientific notation as parameters #group2': function (browser: NightwatchBrowser) {
browser.testContracts('scientific_notation.sol', sources[8]['scientific_notation.sol'], ['test'])
.clickLaunchIcon('udapp')
.click('.udapp_contractActionsContainerSingle > button')
.clickInstance(0)
.clickFunction('inputValue1 - transact (not payable)', { types: 'uint256 _u, int256 _i', values: '"101e3", "-1.13e4"' })
.waitForElementContainsText('*[data-id="terminalJournal"]', '101000', 60000)
.waitForElementContainsText('*[data-id="terminalJournal"]', '-11300', 60000)
.clickFunction('inputValue2 - transact (not payable)', { types: 'uint256 _u', values: '2.345e10' })
.waitForElementContainsText('*[data-id="terminalJournal"]', '2340000000', 60000)
.click('*[data-id="deployAndRunClearInstances"]')
},
'Should Compile and Deploy a contract which define a custom error, the error should be logged in the terminal #group3': function (browser: NightwatchBrowser) { 'Should Compile and Deploy a contract which define a custom error, the error should be logged in the terminal #group3': function (browser: NightwatchBrowser) {
browser.testContracts('customError.sol', sources[4]['customError.sol'], ['C']) browser.testContracts('customError.sol', sources[4]['customError.sol'], ['C'])
.clickLaunchIcon('udapp') .clickLaunchIcon('udapp')
@ -476,5 +489,20 @@ contract C {
} }
` `
} }
}, {
"scientific_notation.sol": {
content: `
import "hardhat/console.sol";
contract test {
function inputValue1 (uint _u, int _i) public {
console.log(_u);
console.logInt(_i);
}
function inputValue2 (uint _u) public {
console.log(_u);
}
}
`
}
} }
] ]

@ -1,5 +1,6 @@
'use strict' 'use strict'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import fromExponential from 'from-exponential';
export function makeFullTypeDefinition (typeDef) { export function makeFullTypeDefinition (typeDef) {
if (typeDef && typeDef.type.indexOf('tuple') === 0 && typeDef.components) { if (typeDef && typeDef.type.indexOf('tuple') === 0 && typeDef.components) {
@ -9,6 +10,10 @@ export function makeFullTypeDefinition (typeDef) {
return typeDef.type return typeDef.type
} }
export const REGEX_SCIENTIFIC = /(\d+\.?\d*)e\d*(\d+)/;
export const REGEX_DECIMAL = /^\d*/
export function encodeParams (funABI, args) { export function encodeParams (funABI, args) {
const types = [] const types = []
if (funABI.inputs && funABI.inputs.length) { if (funABI.inputs && funABI.inputs.length) {
@ -19,6 +24,15 @@ export function encodeParams (funABI, args) {
if (type === 'bool' && args[i] === 'false') { if (type === 'bool' && args[i] === 'false') {
args[i] = false args[i] = false
} }
const regSci = REGEX_SCIENTIFIC.exec(args[i])
const exponents = regSci ? regSci[2] : null
if (regSci && REGEX_DECIMAL.exec(exponents) && (type.indexOf('uint') === 0 || type.indexOf('int') === 0)) {
try {
args[i] = fromExponential(args[i])
} catch (e) {
console.log(e)
}
}
types.push(type.indexOf('tuple') === 0 ? makeFullTypeDefinition(funABI.inputs[i]) : type) types.push(type.indexOf('tuple') === 0 ? makeFullTypeDefinition(funABI.inputs[i]) : type)
if (args.length < types.length) { if (args.length < types.length) {
args.push('') args.push('')

@ -162,6 +162,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"formik": "^2.2.9", "formik": "^2.2.9",
"from-exponential": "1.1.1",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"html-react-parser": "^3.0.4", "html-react-parser": "^3.0.4",
"http-server": "^14.1.1", "http-server": "^14.1.1",

@ -13528,6 +13528,11 @@ fresh@0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=
from-exponential@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/from-exponential/-/from-exponential-1.1.1.tgz#41caff748d22e9c195713802cdac31acbe4b1b83"
integrity sha512-VBE7f5OVnYwdgB3LHa+Qo29h8qVpxhVO9Trlc+AWm+/XNAgks1tAwMFHb33mjeiof77GglsJzeYF7OqXrROP/A==
from2@^1.3.0: from2@^1.3.0:
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/from2/-/from2-1.3.0.tgz#88413baaa5f9a597cfde9221d86986cd3c061dfd" resolved "https://registry.yarnpkg.com/from2/-/from2-1.3.0.tgz#88413baaa5f9a597cfde9221d86986cd3c061dfd"

Loading…
Cancel
Save