Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

armlet

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

armlet - npm Package Compare versions

Comparing version 0.1.9 to 0.2.0

32

index.js

@@ -10,28 +10,2 @@ const url = require('url')

module.exports = (bytecode, apiKey, inputApiUrl = defaultApiUrl) => {
return new Promise((resolve, reject) => {
if (bytecode === undefined) {
throw new TypeError('Please provide a bytecode param.')
}
if (apiKey === undefined) {
throw new TypeError('Please provide an apiKey param.')
}
const apiUrl = url.parse(inputApiUrl)
if (apiUrl.hostname === null) {
throw new TypeError(`${inputApiUrl} is not a valid URL`)
}
requester.do(bytecode, apiKey, apiUrl)
.then(uuid => {
return poller.do(uuid, apiKey, apiUrl)
}).then(issues => {
resolve(issues)
}).catch(err => {
reject(err)
})
})
}
class Client {

@@ -63,7 +37,7 @@ constructor (auth, inputApiUrl = defaultApiUrl) {

return new Promise((resolve, reject) => {
if (options === undefined || options.bytecode === undefined) {
throw new TypeError('Please provide a bytecode option.')
if (options === undefined || options.data === undefined || options.data.deployedBytecode === undefined) {
throw new TypeError('Please provide a deployedBytecode option.')
}
requester.do(options.bytecode, this.apiKey, this.apiUrl)
requester.do(options, this.apiKey, this.apiUrl)
.then(uuid => {

@@ -70,0 +44,0 @@ return poller.do(uuid, this.apiKey, this.apiUrl, undefined, options.timeout)

7

lib/requester.js
const basePath = '/v1/analyses'
exports.do = (bytecode, apiKey, apiUrl) => {
exports.do = (options, apiKey, apiUrl) => {
return new Promise((resolve, reject) => {
const lib = apiUrl.protocol === 'http:' ? require('http') : require('https')
const postData = JSON.stringify({
type: 'bytecode',
contract: bytecode
})
const postData = JSON.stringify(options)

@@ -12,0 +9,0 @@ const postOptions = {

{
"name": "armlet",
"version": "0.1.9",
"version": "0.2.0",
"description": "A Mythril Platform API client.",

@@ -10,3 +10,4 @@ "main": "index.js",

"pretest": "npm run lint",
"test": "mocha --reporter spec --recursive"
"test": "nyc mocha --reporter spec --recursive",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},

@@ -31,4 +32,6 @@ "standard": {

"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"nock": "^9.6.1",
"nyc": "^13.0.1",
"sinon": "^6.1.5",

@@ -35,0 +38,0 @@ "standard": "^11.0.1"

[![CircleCI](https://circleci.com/gh/ConsenSys/armlet.svg?style=svg)](https://circleci.com/gh/ConsenSys/armlet)
[![Coverage Status](https://coveralls.io/repos/github/ConsenSys/armlet/badge.svg?branch=master)](https://coveralls.io/github/ConsenSys/armlet?branch=master)

@@ -33,3 +34,41 @@ # Armlet, a Mythril Platform API client

client.analyze({bytecode: '0xf6'})
const data = {
contractName: 'TestMe',
abi: [
{
constant: false,
inputs: [
{
name: 'first_input',
type: 'uint256',
},
],
name: 'lol',
outputs: [
{
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
],
bytecode: '0xf6...',
deployedBytecode: '0xf6...',
sourceMap: '25:78:1:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;25:78:1;;;;;;;',
deployedSourceMap: '25:78:1:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;25:78:1;;;;;;;',
sourceList: [
'basecontract.sol',
'maincontract.sol',
],
sources: {
'basecontract.sol': '[... escaped source code ...]',
'maincontract.sol': '[... escaped source code ...]',
},
analysisMode: 'full',
};
client.analyze({data})
.then(issues => {

@@ -44,3 +83,3 @@ console.log(issues)

```javascript
client.analyze({bytecode: <contract_bytecode>, timeout: 5000})
client.analyze({data, timeout: 5000})
.then(issues => {

@@ -47,0 +86,0 @@ console.log(issues)

@@ -1,2 +0,2 @@

const analyze = require('../index')
const armlet = require('../index')
const Client = require('../index').Client

@@ -14,3 +14,3 @@ const sinon = require('sinon')

describe('main module', () => {
const bytecode = 'my-bitecode'
const data = {deployedBytecode: 'my-bitecode'}
const apiKey = 'my-apikey'

@@ -37,32 +37,12 @@ const userEmail = 'my-userEmail'

describe('default', () => {
it('should be a function', () => {
analyze.should.be.a('function')
})
it('should return a thenable', () => {
const result = analyze(bytecode, apiKey)
result.then.should.be.a('function')
})
it('should require a bytecode param', async () => {
await analyze(undefined, apiKey).should.be.rejectedWith(TypeError)
})
it('should require an apiKey param', async () => {
await analyze(bytecode).should.be.rejectedWith(TypeError)
})
it('should require a valid api URL if given', async () => {
await analyze(bytecode, apiKey, 'not-a-real-url').should.be.rejectedWith(TypeError)
})
})
describe('Client', () => {
it('should be a function', () => {
analyze.should.be.a('function')
armlet.Client.should.be.a('function')
})
describe('should have a constructor which should', () => {
it('require an auth option', () => {
(() => new Client()).should.throw(TypeError)
})
it('require an apiKey auth option', () => {

@@ -83,3 +63,3 @@ (() => new Client({userEmail: userEmail})).should.throw(TypeError)

instance.apiUrl.should.be.deep.equal(analyze.defaultApiUrl)
instance.apiUrl.should.be.deep.equal(armlet.defaultApiUrl)
})

@@ -102,3 +82,3 @@ })

it('should require a bytecode option', async () => {
it('should require a deployedBytecode option', async () => {
await this.instance.analyze().should.be.rejectedWith(TypeError)

@@ -112,7 +92,7 @@ })

it('should be a function', () => {
analyze.ApiVersion.should.be.a('function')
armlet.ApiVersion.should.be.a('function')
})
it('should return a thenable', () => {
const result = analyze.ApiVersion(apiUrl)
const result = armlet.ApiVersion(apiUrl)

@@ -125,7 +105,7 @@ result.then.should.be.a('function')

it('should be a function', () => {
analyze.OpenApiSpec.should.be.a('function')
armlet.OpenApiSpec.should.be.a('function')
})
it('should return a thenable', () => {
const result = analyze.OpenApiSpec(apiUrl)
const result = armlet.OpenApiSpec(apiUrl)

@@ -142,56 +122,2 @@ result.then.should.be.a('function')

describe('default', () => {
afterEach(() => {
requester.do.restore()
poller.do.restore()
})
it('should chain requester and poller', async () => {
sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
resolve(uuid)
}))
sinon.stub(poller, 'do')
.withArgs(uuid, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
resolve(issues)
}))
await analyze(bytecode, apiKey, apiUrl).should.eventually.equal(issues)
})
it('should reject with requester failures', async () => {
const errorMsg = 'Booom! from requester'
sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
reject(new Error(errorMsg))
}))
sinon.stub(poller, 'do')
.withArgs(uuid, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
resolve(issues)
}))
await analyze(bytecode, apiKey, apiUrl).should.be.rejectedWith(Error, errorMsg)
})
it('should reject with poller failures', async () => {
const errorMsg = 'Booom! from poller'
sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
resolve(uuid)
}))
sinon.stub(poller, 'do')
.withArgs(uuid, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {
reject(new Error(errorMsg))
}))
await analyze(bytecode, apiKey, apiUrl).should.be.rejectedWith(Error, errorMsg)
})
})
describe('Client', () => {

@@ -209,3 +135,3 @@ afterEach(() => {

sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.withArgs({data}, apiKey, parsedApiUrl)
.returns(new Promise(resolve => {

@@ -220,3 +146,3 @@ resolve(uuid)

await this.instance.analyze({bytecode: bytecode}).should.eventually.equal(issues)
await this.instance.analyze({data}).should.eventually.equal(issues)
})

@@ -227,3 +153,3 @@

sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.withArgs({data}, apiKey, parsedApiUrl)
.returns(new Promise((resolve, reject) => {

@@ -238,3 +164,3 @@ reject(new Error(errorMsg))

await this.instance.analyze({bytecode: bytecode}).should.be.rejectedWith(Error, errorMsg)
await this.instance.analyze({data}).should.be.rejectedWith(Error, errorMsg)
})

@@ -245,3 +171,3 @@

sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.withArgs({data}, apiKey, parsedApiUrl)
.returns(new Promise(resolve => {

@@ -256,3 +182,3 @@ resolve(uuid)

await this.instance.analyze({bytecode: bytecode}).should.be.rejectedWith(Error, errorMsg)
await this.instance.analyze({data}).should.be.rejectedWith(Error, errorMsg)
})

@@ -264,3 +190,3 @@

sinon.stub(requester, 'do')
.withArgs(bytecode, apiKey, parsedApiUrl)
.withArgs({data, timeout}, apiKey, parsedApiUrl)
.returns(new Promise(resolve => {

@@ -275,3 +201,3 @@ resolve(uuid)

await this.instance.analyze({bytecode: bytecode, timeout: timeout}).should.eventually.equal(issues)
await this.instance.analyze({data, timeout}).should.eventually.equal(issues)
})

@@ -281,3 +207,3 @@ })

describe('ApiVersion', () => {
const url = `${apiUrl}/${analyze.defaultApiVersion}/version`
const url = `${apiUrl}/${armlet.defaultApiVersion}/version`
afterEach(() => {

@@ -296,3 +222,3 @@ simpleRequester.do.restore()

await analyze.ApiVersion(apiUrl).should.eventually.equal(result)
await armlet.ApiVersion(apiUrl).should.eventually.equal(result)
})

@@ -308,3 +234,3 @@

await analyze.ApiVersion(apiUrl).should.be.rejectedWith(Error, errorMsg)
await armlet.ApiVersion(apiUrl).should.be.rejectedWith(Error, errorMsg)
})

@@ -314,3 +240,3 @@ })

describe('OpenApiSpec', () => {
const url = `${apiUrl}/${analyze.defaultApiVersion}/openapi.yaml`
const url = `${apiUrl}/${armlet.defaultApiVersion}/openapi.yaml`

@@ -330,3 +256,3 @@ afterEach(() => {

await analyze.OpenApiSpec(apiUrl).should.eventually.equal(result)
await armlet.OpenApiSpec(apiUrl).should.eventually.equal(result)
})

@@ -342,3 +268,3 @@

await analyze.OpenApiSpec(apiUrl).should.be.rejectedWith(Error, errorMsg)
await armlet.OpenApiSpec(apiUrl).should.be.rejectedWith(Error, errorMsg)
})

@@ -345,0 +271,0 @@ })

@@ -15,5 +15,5 @@ const nock = require('nock')

const validApiKey = 'valid-api-key'
const bytecode = 'bytecode'
const uuid = 'my-uuid'
const basePath = '/v1/analyses'
const data = {bytecode: '00'}

@@ -26,6 +26,3 @@ it('should request analysis for http API', async () => {

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(200, {

@@ -36,3 +33,3 @@ result: 'Queued',

await requester.do(bytecode, validApiKey, httpApiUrl).should.eventually.equal(uuid)
await requester.do(data, validApiKey, httpApiUrl).should.eventually.equal(uuid)
})

@@ -46,6 +43,3 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(200, {

@@ -56,3 +50,3 @@ result: 'Queued',

await requester.do(bytecode, validApiKey, httpsApiUrl).should.eventually.equal(uuid)
await requester.do(data, validApiKey, httpsApiUrl).should.eventually.equal(uuid)
})

@@ -66,6 +60,3 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(200, {

@@ -76,3 +67,3 @@ result: 'Queued',

await requester.do(bytecode, validApiKey, defaultApiUrl).should.eventually.equal(uuid)
await requester.do(data, validApiKey, defaultApiUrl).should.eventually.equal(uuid)
})

@@ -83,3 +74,3 @@

await requester.do(bytecode, validApiKey, invalidApiHostname).should.be.rejectedWith(Error)
await requester.do(data, validApiKey, invalidApiHostname).should.be.rejectedWith(Error)
})

@@ -93,9 +84,6 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(500)
await requester.do(bytecode, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
await requester.do(data, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
})

@@ -110,6 +98,3 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(429, {

@@ -119,3 +104,3 @@ error: expectedErrorMsg

await requester.do(bytecode, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
await requester.do(data, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
})

@@ -130,6 +115,3 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(400, {

@@ -139,3 +121,3 @@ error: expectedErrorMsg

await requester.do(bytecode, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
await requester.do(data, validApiKey, httpApiUrl).should.be.rejectedWith(Error)
})

@@ -151,9 +133,6 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(401, 'Unauthorized')
await requester.do(bytecode, inValidApiKey, httpApiUrl).should.be.rejectedWith(Error)
await requester.do(data, inValidApiKey, httpApiUrl).should.be.rejectedWith(Error)
})

@@ -167,11 +146,8 @@

})
.post(basePath, {
type: 'bytecode',
contract: bytecode
})
.post(basePath, data)
.reply(200, 'non-json-response')
await requester.do(bytecode, validApiKey, defaultApiUrl).should.be.rejectedWith(SyntaxError)
await requester.do(data, validApiKey, defaultApiUrl).should.be.rejectedWith(SyntaxError)
})
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc