https://github.com/raineorshine/web3-fake-provider
A mock provider class that can be used with Ethereum web3.js
https://github.com/raineorshine/web3-fake-provider
Last synced: 4 months ago
JSON representation
A mock provider class that can be used with Ethereum web3.js
- Host: GitHub
- URL: https://github.com/raineorshine/web3-fake-provider
- Owner: raineorshine
- License: other
- Created: 2016-10-16T00:03:11.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-16T00:41:34.000Z (about 9 years ago)
- Last Synced: 2025-06-19T00:51:52.177Z (5 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 26
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
web3-fake-provider is a mock provider class that can be used with Ethereum `web3.js`. It mocks the behavior of `Web3.providers.HttpProvider`.
Might be useful for testing or having a working web3 instance when your Ethereum node is down.
Originally [part of web3.js](https://github.com/ethereum/web3.js/blob/1.0/test/helpers/FakeHttpProvider.js).
# Install
```sh
npm install web3-fake-provider
```
# Usage
```js
var FakeProvider = require('web3-fake-provider')
var result = '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855';
var provider = new FakeProvider();
web3.setProvider(provider);
provider.injectResult(result);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_accounts');
assert.deepEqual(payload.params, []);
});
assert.deepEqual(result, web3.eth.accounts);
```
# LICENSE
GPL-3.0