This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spec comparing report.gasPrice to effectiveGasPrice
- Loading branch information
1 parent
0977ff9
commit e3b6d1c
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/interface-adapter/test/getTransactionReport.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, it } from "mocha"; | ||
import assert from "assert"; | ||
|
||
import { Server } from "http"; | ||
import BN from "bn.js"; | ||
|
||
import Web3 from "web3"; | ||
import Ganache from "ganache-core"; | ||
|
||
import { createInterfaceAdapter } from "../lib"; | ||
import { | ||
InterfaceAdapter, | ||
Provider, | ||
TransactionReceipt | ||
} from "../lib/adapter/types"; | ||
|
||
const port = 12345; | ||
|
||
async function prepareGanache(): Promise<{ | ||
server: Server; | ||
interfaceAdapter: InterfaceAdapter; | ||
}> { | ||
return new Promise((resolve, reject) => { | ||
const server = Ganache.server(); | ||
server.listen(port, () => { | ||
const interfaceAdapter = createInterfaceAdapter({ | ||
provider: new Web3.providers.HttpProvider(`http://127.0.0.1:${port}`) | ||
}); | ||
resolve({ | ||
server, | ||
interfaceAdapter | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
describe("getTransactionReport", function () { | ||
let provider: any; | ||
let web3: Web3; | ||
|
||
before("Create Provider", async function () { | ||
provider = Ganache.provider({ seed: "decoder", gasLimit: 7000000 }); | ||
web3 = new Web3(provider); | ||
}); | ||
|
||
it("calculates cost given an effectiveGasPrice", async function () { | ||
const preparedGanache = await prepareGanache(); | ||
const accounts = await web3.eth.getAccounts(); | ||
const receipt = await web3.eth.sendTransaction({ | ||
from: accounts[0], | ||
to: accounts[1] | ||
}); | ||
const report = await preparedGanache.interfaceAdapter.getTransactionCostReport( | ||
receipt | ||
); | ||
console.log("report", report); | ||
assert.strictEqual(report.gasPrice, receipt.effectiveGasPrice); | ||
await preparedGanache.server.close(); | ||
}); | ||
}); |