-
Notifications
You must be signed in to change notification settings - Fork 46
Conversation
95f5598
to
f7d4d1a
Compare
f7d4d1a
to
26eec4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 👍
if (!transactionReceipt.events || !transactionReceipt.events.length) { | ||
throw new Error( | ||
`no events found in transaction ${transactionReceipt.transactionHash}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the idea behind throwing an error instead of just returning an empty array in these cases? Isn't that a valid result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was mainly to indicate to a user they may have passed in the wrong transaction. But I could likely do a better check on the method called and throw an error on that instead and return empty from here.
Checking the VG contract, it looks like you can technically submit a completely empty bundle, but I'm sure it would revert when it attempts to validate the empty sig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking through this some more, we likely can't assume someone only will call VG.processBundle
as they may go through a BLSExpander
function instead. I will remove this check. I hope someone doesn't get too frustrated if they pass the wrong txn receipt in...
|
||
expect(() => getOperationResults(txnReceiptMock.object)).to.throw( | ||
`no events found in transaction ${hash}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that TypeMoq
is unnecessarily complex for our use case.
Why not just write:
const txnReceiptMoq = {
transactionHash: hash,
events: undefined,
} as ContractReceipt;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid as
casts when possible as the underlying object technically fails proper typing. typemoq
does add a bit of complexity but it will fully stub out the object, and could be useful in the future for testing more complex OO cases.
I will try without typemoq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it will fully stub out the object
That doesn't seem possible... on this line:
const txnReceiptMock = TypeMoq.Mock.ofType<ContractReceipt>()
ContractReceipt
only exists in the type space, so the actual object produced here must not have any information about ContractReceipt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stub defaults to undefined
return values. There also is a behavior where you can make it throw if you don't define something. But I think at this point is is overkill so I just removed.
|
||
expect(() => getOperationResults(txnReceiptMock.object)).to.throw( | ||
`no WalletOperationProcessed events found in transaction ${hash}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly:
const txnReceiptMock = {
transactionHash: hash,
events: [
{ event: "Other" },
],
} as ContractReceipt;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched
Also |
Should this be updated with #391 ? Should we wait until |
@jacque006 I'd say it's easier to wait until I'm a bit confused about how this branch adds |
@voltrevo I just noticed that as well, forgot to update here. I cherry-picked the core code because I needed the action error decoding for testing the contracts, so I brought over the func. We can use this branch/PR after |
Wait on #377 before updating |
8d4e968
to
24e70a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, left a few questions and minor comments. Also wondering whether this logic needed a test? https://github.com/web3well/bls-wallet/blob/e1e985a82cb36983e47ff8a7dfdf4d39cb2a2357/contracts/clients/src/OperationResults.ts#L175-L178
…ion errors. Change existing contract test case to use getOperationResults. Add typemoq to allow typed mocking. Bump clients patch version.
Remove Typemoq Fix encoding error for test Remove number of events check in getOperationResults Remove other event test case
Add html output to nyc test coverage to more easily find gaps.
Remove unnecessary unknown casts. Split test error encoding functions into one for strings and one for abi encoded messages. Remove magic numbers/slicing to extract error action data and properly generate instead.
bcaa37a
to
2f4d91e
Compare
Ready for re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Just to clarify @jacque006, this doesn't need a test? |
Missed this, kind of. This 'invariant' is actually run when the file is loaded into the JS runtime: https://github.com/web3well/bls-wallet/blob/9f4064eef9de499b4d959b6462180b5bd885d5f3/contracts/clients/src/OperationResults.ts#L6-L13 This means that if those The one thing we are not testing here is what happens when the assert fails. Normally in coverage detection a branch statement like: if (somethingIsWrong) {
throw new Error("you done goofed");
} Would require you to run the function this is in twice, testing the true/false paths for this statement to get full branch coverage. However, since that selector check is an We could export |
Going to merge w/o @voltrevo 's approval, believe all their comments are addressed. Can follow up with additional work if other issues need to be addressed. |
What is this PR doing?
AddDone in earlier PRgetOperationResults
client function to more easily parse operation results & errors.AddRemovedtypemoq
to clients to aid in mocking for unit tests.OperationResults.ts
logic.nyc
test coverage instrumentation to identify gaps in our client tests.How can these changes be manually tested?
cd ./contracts/clients && yarn test
Does this PR resolve or contribute to any issues?
Resolves #365
Checklist
Guidelines
resolve conversation
button is for reviewers, not authorsTODO
decodeError
code branchesEnforce client test coverage https://www.npmjs.com/package/nyc#coverage-thresholdsWill be slightly more involved than originally expected, broke off into Enforce client test coverage #436