set the provider only when it is initiated

pull/3448/head
yann300 2 years ago committed by Aniket
parent e5c6921d93
commit 40f907d95f
  1. 49
      apps/remix-ide-e2e/src/tests/transactionExecution.test.ts
  2. 13
      apps/remix-ide/src/blockchain/providers/vm.js
  3. 13
      apps/remix-ide/src/blockchain/providers/worker-vm.ts

@ -213,7 +213,28 @@ module.exports = {
'uint256 num': '24'
}
})
.end()
},
'Should switch to the mainnet VM fork and execute a tx to query ENS #group5': function (browser: NightwatchBrowser) {
let addressRef
browser
.addFile('mainnet_ens.sol', sources[7]['mainnet_ens.sol'])
.clickLaunchIcon('solidity')
.setSolidityCompilerVersion('soljson-v0.8.17+commit.8df45f5f.js')
.clickLaunchIcon('udapp')
.switchEnvironment('vm-mainnet-fork')
.waitForElementPresent('select[data-id="runTabSelectAccount"] option[value="0xdD870fA1b7C4700F2BD7f44238821C26f7392148"]') // wait for the udapp to load the list of accounts
.selectContract('MyResolver')
.createContract('')
.clickInstance(0)
.getAddressAtPosition(0, (address) => {
addressRef = address
})
.clickFunction('resolve - call')
.perform((done) => {
browser.verifyCallReturnValue(addressRef, ['0:address: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'])
.perform(() => done())
})
}
}
@ -431,5 +452,31 @@ contract C {
}
}`
}
}, {
'mainnet_ens.sol': {
content:
`
import "https://github.com/ensdomains/ens-contracts/blob/master/contracts/utils/NameEncoder.sol";
abstract contract ENS {
function resolver(bytes32 node) public virtual view returns (Resolver);
}
abstract contract Resolver {
function addr(bytes32 node) public virtual view returns (address);
}
contract MyResolver {
// Same address for Mainet, Ropsten, Rinkerby, Gorli and other networks;
ENS ens = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
function resolve() public view returns(address) {
(,bytes32 node) = NameEncoder.dnsEncodeName("vitalik.eth");
Resolver resolver = ens.resolver(node);
return resolver.addr(node);
}
}
`
}
}
]

@ -24,15 +24,13 @@ class VMProvider {
this.worker = new Worker(new URL('./worker-vm', import.meta.url))
const provider = this.executionContext.getProviderObject()
this.worker.postMessage({ cmd: 'init', fork: this.executionContext.getCurrentFork(), nodeUrl: provider?.options['nodeUrl'], blockNumber: provider?.options['blockNumber']})
let incr = 0
const stamps = {}
this.worker.addEventListener('message', (msg) => {
if (stamps[msg.data.stamp]) {
if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
stamps[msg.data.stamp](msg.data.error, msg.data.result)
}
})
} else if (msg.data.cmd === 'initiateResult') {
if (!msg.data.error) {
this.provider = {
sendAsync: (query, callback) => {
const stamp = Date.now() + incr
@ -46,6 +44,11 @@ class VMProvider {
this.accounts = {}
this.executionContext.setWeb3(this.executionContext.getProvider(), this.web3)
}
}
})
this.worker.postMessage({ cmd: 'init', fork: this.executionContext.getCurrentFork(), nodeUrl: provider?.options['nodeUrl'], blockNumber: provider?.options['blockNumber']})
}
// TODO: is still here because of the plugin API
// can be removed later when we update the API

@ -7,7 +7,18 @@ self.onmessage = (e: MessageEvent) => {
case 'init':
{
provider = new Provider({ fork: data.fork, nodeUrl: data.nodeUrl, blockNumber: data.blockNumber })
if (provider) provider.init()
provider.init().then(() => {
self.postMessage({
cmd: 'initiateResult',
stamp: data.stamp
})
}).catch((error) => {
self.postMessage({
cmd: 'initiateResult',
error,
stamp: data.stamp
})
})
break
}
case 'sendAsync':

Loading…
Cancel
Save