Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

sdk: getJob() result sometimes includes an object instead of a string for transcoder field #319

Closed
yondonfu opened this issue Jan 31, 2019 · 1 comment · Fixed by #318
Closed
Labels
area: sdk Relates to packages/sdk. type: bug something's not working correctly

Comments

@yondonfu
Copy link
Member

Describe the bug (required)
A clear and concise description of what the bug is.

The getJob() function in the SDK sometimes includes an object instead of a string for the transcoder field. As a result, the tests for getJob() which validate the schema of the returned object fail.

getJob() executes the following operations:

  1. Calls the JobsManager contract to fetch job data
  2. Checks if the transcoder field in the returned job data is null or empty
  3. If the transcoder field is null or empty, calls electActiveTranscoder() to compute the transcoder address assigned to the job [1]
  4. Sets transcoder field in the job to the returned address from electActiveTranscoder()

We currently use the ethjs library for ETH contract related interactions. It seems that ethjs returns objects for contract calls even if the there is only a single value returned (see this issue). In other areas of the SDK, the headToString() helper is used to extract the first value from the object returned by ethjs. We can probably wrap the result of electActiveTranscoder() with this helper to fix this issue.

[1] The transcoder field in a job will be populated if the transcoder called claimWork() on the JobsManager contract at least once for the job. If the transcoder never called claimWork() for a job, the transcoder field will not be populated in the contract. However, the transcoder address assigned to the job can be computed using electActiveTranscoder().

Expected behavior (required)
A clear and concise description of what you expected to happen.

Tests should pass and SDK functions should return strings for ETH addresses and not objects.

To Reproduce (required)
Steps to reproduce the behavior:

  1. Switch to the branch in sdk: fix inconsistent return type of getJob() #318
  2. Run yarn test in the sdk package
  3. Observe failing tests

Device (required):

  • Device: MacBook Pro
  • OS: OSX

Console logs (optional)

lerna ERR! Unhandled Rejection: src/index.test.js
lerna ERR!   ValidationError: transcoder must be a `string` type, but the final value was: `{
lerna ERR!   Object.createError (/home/circleci/repo/node_modules/yup/lib/util/createValidation.js:71:21)
lerna ERR! Object.test (/home/circleci/repo/node_modules/yup/lib/mixed.js:443:76)
lerna ERR! runTest (/home/circleci/repo/node_modules/yup/lib/util/createValidation.js:34:23)
lerna ERR! StringSchema.validate [as _typeError] (/home/circleci/repo/node_modules/yup/lib/util/createValidation.js:116:12)
lerna ERR! StringSchema._validate (/home/circleci/repo/node_modules/yup/lib/mixed.js:275:49)
lerna ERR! StringSchema.validate (/home/circleci/repo/node_modules/yup/lib/mixed.js:303:19)
lerna ERR! /home/circleci/repo/node_modules/yup/lib/object.js:212:44
lerna ERR! /home/circleci/repo/node_modules/yup/lib/object.js:196:39
lerna ERR! SynchronousPromise._applyNextHandler (/home/circleci/repo/node_modules/synchronous-promise/index.js:99:26)
lerna ERR! SynchronousPromise._applyNext (/home/circleci/repo/node_modules/synchronous-promise/index.js:95:17)
lerna ERR! SynchronousPromise.then (/home/circleci/repo/node_modules/synchronous-promise/index.js:29:17)
lerna ERR! ObjectSchema._validate (/home/circleci/repo/node_modules/yup/lib/object.js:187:135)
lerna ERR! ObjectSchema.validateSync (/home/circleci/repo/node_modules/yup/lib/mixed.js:312:12)
lerna ERR! validateSync (src/index.test.js:339:12)
@yondonfu yondonfu added type: bug something's not working correctly area: sdk Relates to packages/sdk. labels Jan 31, 2019
@iameli
Copy link
Contributor

iameli commented Jan 31, 2019

Right on, thanks for the thorough write-up. I'll tackle this as I unbreak #316

iameli added a commit to iameli/livepeerjs that referenced this issue Jan 31, 2019
Fixes livepeer#319

Two tweaks here — `beforeEach` instead of `before` and some tweaks
to async loops so they actually wait until the end — forEach will
return immediately and cause a false positive.
yondonfu pushed a commit that referenced this issue Feb 1, 2019
Fixes #319

Two tweaks here — `beforeEach` instead of `before` and some tweaks
to async loops so they actually wait until the end — forEach will
return immediately and cause a false positive.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: sdk Relates to packages/sdk. type: bug something's not working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants