fix bytecode comparison

pull/5370/head
yann300 2 years ago committed by Aniket
parent 2e21845a5e
commit f25b095046
  1. 43
      apps/remix-ide-e2e/src/tests/erc721.test.ts
  2. 17
      libs/remix-lib/src/util.ts

@ -0,0 +1,43 @@
'use strict'
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
import examples from '../examples/example-contracts'
const sources = []
module.exports = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done)
},
'@sources': function () {
return sources
},
'Deploy SampleERC721 whose bytecode is very similar to ERC721': function (browser: NightwatchBrowser) {
browser.click('*[data-id="workspaceCreate"]')
// create contract
.waitForElementVisible('*[data-id="modalDialogCustomPromptTextCreate"]')
.waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] > button')
// eslint-disable-next-line dot-notation
.execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextCreate"]')['value'] = 'workspace_erc721' })
.click('select[id="wstemplate"]')
.click('select[id="wstemplate"] option[value=ozerc721]')
.waitForElementPresent('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok')
.execute(function () { (document.querySelector('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') as HTMLElement).click() })
.pause(100)
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts/SampleERC721.sol"]')
// deploy contract
.clickLaunchIcon('udapp')
.selectContract('SampleERC721')
.createContract('E, E')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
'decoded input': {
'string tokenName': 'E',
'string tokenSymbol': 'E'
}
}).end()
}
}

@ -184,6 +184,15 @@ export function cborEncodedValueExtraction () {
return /64697066735822([0-9a-f]{68})64736f6c6343([0-9a-f]{6})0033$/ return /64697066735822([0-9a-f]{68})64736f6c6343([0-9a-f]{6})0033$/
} }
/**
* return a regex which extract the input parameters from the bytecode
*
* @return {RegEx}
*/
export function inputParametersExtraction () {
return /64697066735822[0-9a-f]{68}64736f6c6343[0-9a-f]{6}0033(.*)$/
}
export function extractcborMetadata (value) { export function extractcborMetadata (value) {
return value.replace(cborEncodedValueExtraction(), '') return value.replace(cborEncodedValueExtraction(), '')
} }
@ -195,6 +204,10 @@ export function extractSwarmHash (value) {
return value return value
} }
export function extractinputParameters (value) {
return value.replace(inputParametersExtraction(), '')
}
/** /**
* Compare bytecode. return true if the code is equal (handle swarm hash and library references) * Compare bytecode. return true if the code is equal (handle swarm hash and library references)
* @param {String} code1 - the bytecode that is actually deployed (contains resolved library reference and a potentially different swarmhash) * @param {String} code1 - the bytecode that is actually deployed (contains resolved library reference and a potentially different swarmhash)
@ -218,14 +231,16 @@ export function compareByteCode (code1, code2) {
code2 = replaceLibReference(code2, pos) code2 = replaceLibReference(code2, pos)
code1 = replaceLibReference(code1, pos) code1 = replaceLibReference(code1, pos)
} }
code1 = extractinputParameters(code1)
code1 = extractSwarmHash(code1) code1 = extractSwarmHash(code1)
code1 = extractcborMetadata(code1) code1 = extractcborMetadata(code1)
code2 = extractinputParameters(code2)
code2 = extractSwarmHash(code2) code2 = extractSwarmHash(code2)
code2 = extractcborMetadata(code2) code2 = extractcborMetadata(code2)
if (code1 && code2) { if (code1 && code2) {
const compare = stringSimilarity.compareTwoStrings(code1, code2) const compare = stringSimilarity.compareTwoStrings(code1, code2)
return compare > 0.93 return compare == 1
} }
return false return false

Loading…
Cancel
Save