embark/dapps/tests/contracts/contracts.js

78 lines
1.7 KiB
JavaScript
Raw Normal View History

module.exports = {
2017-02-10 00:38:02 +00:00
"default": {
"versions": {
"solc": "0.4.26"
},
"dappConnection": [
fix(@embark/dapps): Contracts app test failure During `embark test`, the contracts dapp was throwing an error: ``` connection not open on send() Error: Invalid JSON RPC response: "" at Object.InvalidResponse (/Users/michael/repos/embark/node_modules/web3-core-helpers/src/errors.js:42:16) at XMLHttpRequest.request.onreadystatechange (/Users/michael/repos/embark/node_modules/web3-providers-http/src/index.js:92:32) at XMLHttpRequestEventTarget.dispatchEvent (/Users/michael/repos/embark/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13) at XMLHttpRequest._setReadyState (/Users/michael/repos/embark/node_modules/xhr2-cookies/xml-http-request.ts:219:8) at XMLHttpRequest._onHttpRequestError (/Users/michael/repos/embark/node_modules/xhr2-cookies/xml-http-request.ts:379:8) at ClientRequest.<anonymous> (/Users/michael/repos/embark/node_modules/xhr2-cookies/xml-http-request.ts:266:37) at ClientRequest.emit (events.js:198:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:198:13) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at process._tickCallback (internal/process/next_tick.js:63:19) (node:75120) UnhandledPromiseRejectionWarning: Error: Provider not set or invalid ... ``` This was due to the fact that during testing, the Ganache VM **provider** is used as the blockchain node, instead of spinning up an instance of Ganache. Due to this, there is no HTTP nor WebSockets RPC endpoint opened on the VM node, and the contracts dapp was not able to connect to the node during tests. Add `$EMBARK` to the contract config’s `dappConnection` list, so that the contract test dapp can successfully connect to Embark’s proxy, which ultimately communicates with the Ganache VM. As a side note, without `$EMBARK` in the `dappConnection` list, the tests could run successfully when using `embark test —node=embark`. This succeeds because the geth node exposes the RPC WebSockets endpoint that the contracts app connects to on `ws://localhost:8546`.
2019-12-16 07:42:44 +00:00
"$EMBARK",
"$WEB3",
2018-02-08 00:39:11 +00:00
"ws://localhost:8546",
"http://localhost:8550",
"http://localhost:8545",
"http://localhost:8550"
],
2017-02-10 00:38:02 +00:00
"gas": "auto",
"deploy": {
2017-07-16 18:11:37 +00:00
"Ownable": {
"deploy": false
},
2017-02-10 00:38:02 +00:00
"SimpleStorage": {
2018-02-08 00:39:11 +00:00
"fromIndex": 0,
"args": [100]
2017-02-10 00:38:02 +00:00
},
"AnotherStorage": {
"args": [
"$SimpleStorage",
"embark.eth"
2017-02-10 00:38:02 +00:00
]
2017-02-10 02:05:45 +00:00
},
"Token": {
"deploy": false,
"args": [1000]
},
"Test": {
"onDeploy": ["Test.methods.changeAddress('$MyToken')"]
},
2017-02-10 02:05:45 +00:00
"MyToken": {
"instanceOf": "Token"
},
"MyToken2": {
"instanceOf": "Token",
"args": [200]
2017-02-10 02:05:45 +00:00
},
"AlreadyDeployedToken": {
2017-10-07 19:20:51 +00:00
"address": "0xece374063fe5cc7efbaca0a498477cada94e5ad6",
2017-02-10 02:05:45 +00:00
"instanceOf": "Token"
2017-12-19 19:07:48 +00:00
},
"MyToken3": {
"instanceOf": "Tokn"
},
"ContractArgs": {
"args": {
"initialValue": 123,
"_addresses": ["$MyToken2", "$SimpleStorage"]
}
},
"SomeContract": {
"args": [
["$MyToken2", "$SimpleStorage"],
100
]
2017-02-10 00:38:02 +00:00
}
2017-12-21 16:21:36 +00:00
},
afterDeploy: async ({contracts, web3}) => {
await contracts.Test.methods.changeAddress(contracts.MyToken.options.address).send();
const accounts = await web3.eth.getAccounts();
await contracts.Test.methods.changeAddress(accounts[0]).send();
}
},
"development": {
"deploy": {
"MyToken2": {
"instanceOf": "Token",
"args": [2000]
}
}
2017-02-10 00:38:02 +00:00
}
};