Simulation logging, hopefully address function assertion lifetime issue

This commit is contained in:
Michael Zhu
2019-11-26 13:47:11 -08:00
parent d11cdcd5d2
commit faf306ad23
13 changed files with 227 additions and 194 deletions

View File

@@ -23,14 +23,11 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
describe('executeAsync', () => {
it('should call the before function with the provided arguments', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
exampleContract.returnInteger.bind(exampleContract),
{
before: async (args: [BigNumber], txData: Partial<TxData>) => {
sideEffectTarget = randomInput;
},
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(exampleContract, 'returnInteger', {
before: async (args: [BigNumber], txData: Partial<TxData>) => {
sideEffectTarget = randomInput;
},
);
});
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
await assertion.executeAsync([randomInput], {});
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
@@ -38,26 +35,23 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should call the after function with the provided arguments', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
exampleContract.returnInteger.bind(exampleContract),
{
after: async (
_beforeInfo: any,
_result: FunctionResult,
args: [BigNumber],
txData: Partial<TxData>,
) => {
[sideEffectTarget] = args;
},
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(exampleContract, 'returnInteger', {
after: async (
_beforeInfo: any,
_result: FunctionResult,
args: [BigNumber],
txData: Partial<TxData>,
) => {
[sideEffectTarget] = args;
},
);
});
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
await assertion.executeAsync([randomInput], {});
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
});
it('should not fail immediately if the wrapped function fails', async () => {
const assertion = new FunctionAssertion<[], {}, void>(exampleContract.emptyRevert.bind(exampleContract));
const assertion = new FunctionAssertion<[], {}, void>(exampleContract, 'emptyRevert');
await assertion.executeAsync([], {});
});
@@ -65,7 +59,8 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion<[BigNumber], BigNumber, BigNumber>(
exampleContract.returnInteger.bind(exampleContract),
exampleContract,
'returnInteger',
{
before: async (_args: [BigNumber], _txData: Partial<TxData>) => {
return randomInput;
@@ -86,19 +81,16 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should pass the result from the function call to "after"', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
exampleContract.returnInteger.bind(exampleContract),
{
after: async (
_beforeInfo: any,
result: FunctionResult,
_args: [BigNumber],
_txData: Partial<TxData>,
) => {
sideEffectTarget = result.data;
},
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(exampleContract, 'returnInteger', {
after: async (
_beforeInfo: any,
result: FunctionResult,
_args: [BigNumber],
_txData: Partial<TxData>,
) => {
sideEffectTarget = result.data;
},
);
});
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
await assertion.executeAsync([randomInput], {});
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
@@ -106,21 +98,13 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should pass the receipt from the function call to "after"', async () => {
let sideEffectTarget: TransactionReceiptWithDecodedLogs;
const assertion = new FunctionAssertion<[string], void, void>(
exampleContract.emitEvent.bind(exampleContract),
{
after: async (
_beforeInfo: any,
result: FunctionResult,
_args: [string],
_txData: Partial<TxData>,
) => {
if (result.receipt) {
sideEffectTarget = result.receipt;
}
},
const assertion = new FunctionAssertion<[string], void, void>(exampleContract, 'emitEvent', {
after: async (_beforeInfo: any, result: FunctionResult, _args: [string], _txData: Partial<TxData>) => {
if (result.receipt) {
sideEffectTarget = result.receipt;
}
},
);
});
const input = 'emitted data';
await assertion.executeAsync([input], {});
@@ -135,19 +119,11 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should pass the error to "after" if the function call fails', async () => {
let sideEffectTarget: Error;
const assertion = new FunctionAssertion<[string], void, void>(
exampleContract.stringRevert.bind(exampleContract),
{
after: async (
_beforeInfo: any,
result: FunctionResult,
_args: [string],
_txData: Partial<TxData>,
) => {
sideEffectTarget = result.data;
},
const assertion = new FunctionAssertion<[string], void, void>(exampleContract, 'stringRevert', {
after: async (_beforeInfo: any, result: FunctionResult, _args: [string], _txData: Partial<TxData>) => {
sideEffectTarget = result.data;
},
);
});
const message = 'error message';
await assertion.executeAsync([message], {});