-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added truffle assertions typings (#738)
This PR includes changes that were a part of #736 and that require some special attention. This PR moves the generated truffle typings to the `build/` directory, so we can use the `types/` directory for manually created type definitions. Added typings for the `truffle-assertions` npm package for use in the truffle tests. ### Test Plan CI!
- Loading branch information
Showing
5 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,8 +4,9 @@ coverage.json | |
deploy/* | ||
node_modules/* | ||
build/ | ||
types/ | ||
|
||
package-lock.json | ||
yarn-error.log | ||
|
||
.idea/ | ||
.vscode/ | ||
|
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
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
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,56 @@ | ||
/** | ||
* Typings for `truffle-assertions` package. | ||
*/ | ||
|
||
declare module "truffle-assertions" { | ||
import "@openeth/truffle-typings" | ||
import { TransactionReceipt } from "web3-core" | ||
|
||
class InvalidTxResultError extends Error {} | ||
|
||
const enum ErrorType { | ||
REVERT = "revert", | ||
INVALID_OPCODE = "invalid opcode", | ||
OUT_OF_GAS = "out of gas", | ||
INVALID_JUMP = "invalid JUMP", | ||
} | ||
|
||
interface TransactionResult { | ||
tx: string; | ||
receipt: TransactionReceipt; | ||
logs: Truffle.TransactionLog[]; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type FilterOrObject = ((data: any) => boolean) | any | ||
|
||
interface TruffleAssert { | ||
eventEmitted: ( | ||
result: TransactionResult, | ||
eventType: string, | ||
filterOrObject?: FilterOrObject, | ||
message?: string, | ||
) => void; | ||
eventNotEmitted: ( | ||
result: TransactionResult, | ||
eventType: string, | ||
filterOrObject?: FilterOrObject, | ||
message?: string, | ||
) => void; | ||
prettyPrintEmittedEvents: (result: TransactionResult, indentationSize: number) => void; | ||
createTransactionResult: <T>( | ||
contract: Truffle.Contract<T>, | ||
transactionHash: string, | ||
) => TransactionResult; | ||
|
||
passes: (asyncFn: Promise<{}>, message?: string) => void; | ||
fails: (asyncFn: Promise<{}>, errorType: ErrorType, reason?: string, message?: string) => void; | ||
reverts: (asyncFn: Promise<{}>, reason?: string, message?: string) => void; | ||
|
||
ErrorType: ErrorType; | ||
InvalidTxResultError: InvalidTxResultError; | ||
} | ||
|
||
const truffleAssert: TruffleAssert | ||
export = truffleAssert | ||
} |
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,7 @@ | ||
/** | ||
* Include generated tuffle typings for tests. | ||
*/ | ||
|
||
/// <reference types="../../build/truffle-typings/merge" /> | ||
|
||
export * from "../../build/truffle-typings" |