Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Adjust transaction parameters and prefixed string normalizers #257

Merged
merged 2 commits into from
Jul 18, 2019

Conversation

JamesLefrere
Copy link
Contributor

@JamesLefrere JamesLefrere commented Jul 17, 2019

This PR makes some changes to transactions created with ethereumjs-tx such that the chain and to properties are supplied correctly; this fixes a bug where the recovery param wasn't validated correctly.

Changes

  • Adjust transaction params
    • Adjust parameters for ethereumjs-tx transactions (recent breaking changes) and ensure that the chain ID is supplied; this fixes a bug where the recovery param wasn't validated correctly
    • Fix logic for supplying a to property for transactions (it can also be null, not just undefined)
    • Fix some Flow types
    • Fix some comments
    • Update/fix tests
  • Minor normalizers refactor
    • Fix Flow errors for string normalizers, require a string value
    • Use a bound function for address/hex sequence normalizers

@@ -248,7 +248,7 @@ export const transactionObjectValidator = ({
* Only check if the address (`to` prop) is in the correct
* format, if one was provided in the initial transaction object
*/
if (typeof to !== 'undefined') {
if (to) {
Copy link
Contributor Author

@JamesLefrere JamesLefrere Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A truthy check should suffice for to; it can be null or undefined (or a string).

/*
* Encrypted JSON Keystore
*/
keystore: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow showed me that these had to be removed, because they conflicted with the getters (which are typed appropriately).

@@ -297,7 +297,7 @@ export const signMessage = async ({
const toSign = messageOrDataValidator({ message, messageData });
warning(messages.messageSignatureOnlyTrezor);
try {
const { signature: signedMessage } = await payloadListener({
const { signature: signedMessage = '' } = await payloadListener({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow showed that this was necessary; signature is optional in the return value, but I'm not sure whether this is a problem.

@@ -189,6 +193,9 @@ describe('`Trezor` Hardware Wallet Module Static Methods', () => {
);
});
test('Signs a transaction without a destination address', async () => {
payloadListener.mockImplementation(() => ({
Copy link
Contributor Author

@JamesLefrere JamesLefrere Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was silently failing :/ (reported as RUNS not PASS)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

* Fix Flow errors for string normalizers, require a string value
* Use a bound function for address/hex sequence normalizers
* Adjust parameters for `ethereumjs-tx` transactions (recent breaking changes) and ensure that the chain ID is supplied; this fixes a bug where the recovery param wasn't validated correctly
* Fix logic for supplying a `to` property for transactions (it can also be `null`, not just `undefined`)
* Fix some Flow types
* Fix some comments
* Update/fix tests
@rdig rdig added this to the Sprint 30 milestone Jul 18, 2019
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once a again, very nice job @JamesLefrere 💯

/**
* Nomalize an Ethereum address
* Normalize an Ethereum address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, you even spell checked my comments. Top marks 💯

@@ -189,6 +193,9 @@ describe('`Trezor` Hardware Wallet Module Static Methods', () => {
);
});
test('Signs a transaction without a destination address', async () => {
payloadListener.mockImplementation(() => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

* provided in the initial transaction object.
*/
typeof to !== 'undefined' ? { to: addressNormalizer(to) } : {},
),
...(to ? { to: addressNormalizer(to) } : {}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to manually check the Trezor service, since I remember it going crazy if we passed in values it didn't expect.

@rdig rdig merged commit 101a622 into master Jul 18, 2019
@rdig rdig deleted the fix/ethereumjs-tx-params branch July 18, 2019 08:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants