-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test/reporter): log tx functions during tests
Extract function log function to utils to use in the reporter to show txs in tests
- Loading branch information
1 parent
89753c1
commit 87d92b6
Showing
6 changed files
with
304 additions
and
136 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
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,73 @@ | ||
import {Contract} from "embark"; | ||
import {ABIDefinition} from "web3/eth/abi"; | ||
|
||
const utils = require("./utils"); | ||
|
||
export interface AddressToContract { | ||
name: string; | ||
functions: { [functionName: string]: FunctionSignature; }; | ||
silent?: boolean; | ||
} | ||
|
||
export interface AddressToContractArray { | ||
[address: string]: AddressToContract; | ||
} | ||
|
||
export interface FunctionSignature { | ||
abi: ABIDefinition; | ||
functionName?: string; | ||
name: string; | ||
} | ||
|
||
export function getAddressToContract(contractsList: Contract[], addressToContract: AddressToContractArray): AddressToContractArray { | ||
if (!contractsList) { | ||
return addressToContract; | ||
} | ||
contractsList.forEach((contract: Contract) => { | ||
if (!contract.deployedAddress) { | ||
return; | ||
} | ||
|
||
const address = contract.deployedAddress.toLowerCase(); | ||
if (addressToContract[address]) { | ||
return; | ||
} | ||
const funcSignatures: { [name: string]: FunctionSignature } = {}; | ||
contract.abiDefinition | ||
.filter((func: ABIDefinition) => func.type === "function") | ||
.map((func: ABIDefinition) => { | ||
const name = `${func.name}(${func.inputs ? func.inputs.map((input) => input.type).join(",") : ""})`; | ||
funcSignatures[utils.sha3(name).substring(0, 10)] = { | ||
abi: func, | ||
functionName: func.name, | ||
name, | ||
}; | ||
}); | ||
|
||
addressToContract[address] = { | ||
functions: funcSignatures, | ||
name: contract.className, | ||
silent: contract.silent, | ||
}; | ||
}); | ||
return addressToContract; | ||
} | ||
|
||
export function getTransactionParams(contract: AddressToContract, transactionInput: string): object { | ||
const func = contract.functions[transactionInput.substring(0, 10)]; | ||
const functionName = func.functionName; | ||
|
||
const decodedParameters = utils.decodeParams(func.abi.inputs, transactionInput.substring(10)); | ||
let paramString = ""; | ||
if (func.abi.inputs) { | ||
func.abi.inputs.forEach((input) => { | ||
const quote = input.type.indexOf("int") === -1 ? '"' : ""; | ||
paramString += quote + decodedParameters[input.name] + quote + ", "; | ||
}); | ||
paramString = paramString.substring(0, paramString.length - 2); | ||
} | ||
return { | ||
functionName, | ||
paramString, | ||
}; | ||
} |
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
Oops, something went wrong.