Remove unused JavaScript tests for RPC API (#737)

This commit is contained in:
Pedro Pombeiro 2018-03-16 18:49:42 +01:00 committed by GitHub
parent 3b92b61ef1
commit d84510de92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 1349 deletions

1
.gitignore vendored
View File

@ -64,3 +64,4 @@ coverage.html
Session.vim Session.vim
.undodir/* .undodir/*
/.idea/

View File

@ -102,7 +102,8 @@ xgo:
go get github.com/karalabe/xgo go get github.com/karalabe/xgo
generate: ##@other Regenerate assets and other auto-generated stuff generate: ##@other Regenerate assets and other auto-generated stuff
cp ./_assets/node_modules/web3/dist/web3.min.js ./static/scripts/web3.js cd _assets/static && npm install
cp ./_assets/static/node_modules/web3/dist/web3.min.js ./static/scripts/web3.js
go generate ./static go generate ./static
rm ./static/scripts/web3.js rm ./static/scripts/web3.js

View File

@ -1,417 +0,0 @@
{
"name": "status-js",
"version": "0.9.8",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"assertion-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz",
"integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=",
"dev": true
},
"axios": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.17.1.tgz",
"integrity": "sha1-LY4+XQvb1zJ/kbyBT1xXZg+Bgk0=",
"dev": true,
"requires": {
"follow-redirects": "1.2.6",
"is-buffer": "1.1.6"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
},
"bignumber.js": {
"version": "git://github.com/status-im/bignumber.js.git#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"dev": true
},
"brace-expansion": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
"dev": true,
"requires": {
"balanced-match": "1.0.0",
"concat-map": "0.0.1"
}
},
"browser-stdout": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
"dev": true
},
"chai": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
"integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=",
"dev": true,
"requires": {
"assertion-error": "1.0.2",
"check-error": "1.0.2",
"deep-eql": "3.0.1",
"get-func-name": "2.0.0",
"pathval": "1.1.0",
"type-detect": "4.0.5"
}
},
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
"dev": true
},
"commander": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
"dev": true,
"requires": {
"graceful-readlink": "1.0.1"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"crypto-js": {
"version": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
"integrity": "sha1-cV8HC/YBTyrpkqmLOSkli3E/CNU=",
"dev": true
},
"debug": {
"version": "2.6.8",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz",
"integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"deep-eql": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
"dev": true,
"requires": {
"type-detect": "4.0.5"
}
},
"diff": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz",
"integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
},
"follow-redirects": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.2.6.tgz",
"integrity": "sha512-FrMqZ/FONtHnbqO651UPpfRUVukIEwJhXMfdr/JWAmrDbeYBu773b1J6gdWDyRIj4hvvzQEHoEOTrdR8o6KLYA==",
"dev": true,
"requires": {
"debug": "3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"get-func-name": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
"dev": true
},
"glob": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
"dev": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"graceful-readlink": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=",
"dev": true
},
"growl": {
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz",
"integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=",
"dev": true
},
"has-flag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz",
"integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=",
"dev": true
},
"he": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
"dev": true
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
},
"json3": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
"integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
"dev": true
},
"lodash._baseassign": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
"integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=",
"dev": true,
"requires": {
"lodash._basecopy": "3.0.1",
"lodash.keys": "3.1.2"
}
},
"lodash._basecopy": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
"integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
"dev": true
},
"lodash._basecreate": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz",
"integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=",
"dev": true
},
"lodash._getnative": {
"version": "3.9.1",
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
"integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
"dev": true
},
"lodash._isiterateecall": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
"integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
"dev": true
},
"lodash.create": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz",
"integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=",
"dev": true,
"requires": {
"lodash._baseassign": "3.2.0",
"lodash._basecreate": "3.0.3",
"lodash._isiterateecall": "3.0.9"
}
},
"lodash.isarguments": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
"integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
"dev": true
},
"lodash.isarray": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
"dev": true
},
"lodash.keys": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
"integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
"dev": true,
"requires": {
"lodash._getnative": "3.9.1",
"lodash.isarguments": "3.1.0",
"lodash.isarray": "3.0.4"
}
},
"minimatch": {
"version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=",
"dev": true,
"requires": {
"brace-expansion": "1.1.8"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"mocha": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.3.tgz",
"integrity": "sha512-/6na001MJWEtYxHOV1WLfsmR4YIynkUEhBwzsb+fk2qmQ3iqsi258l/Q2MWHJMImAcNpZ8DEdYAK72NHoIQ9Eg==",
"dev": true,
"requires": {
"browser-stdout": "1.3.0",
"commander": "2.9.0",
"debug": "2.6.8",
"diff": "3.2.0",
"escape-string-regexp": "1.0.5",
"glob": "7.1.1",
"growl": "1.9.2",
"he": "1.1.1",
"json3": "3.3.2",
"lodash.create": "3.1.1",
"mkdirp": "0.5.1",
"supports-color": "3.1.2"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"pathval": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
"dev": true
},
"requirejs": {
"version": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz",
"integrity": "sha1-YXuay7yzNlQO9JFNeQMjqNS4YbA=",
"dev": true
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
"dev": true,
"requires": {
"glob": "7.1.1"
}
},
"supports-color": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
"integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
"dev": true,
"requires": {
"has-flag": "1.0.0"
}
},
"type-detect": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.5.tgz",
"integrity": "sha512-N9IvkQslUGYGC24RkJk1ba99foK6TkwC2FHAEBlQFBP0RxQZS8ZpJuAZcwiY/w9ZJHFQb1aOXBI60OdxhTrwEQ==",
"dev": true
},
"utf8": {
"version": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
"integrity": "sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY=",
"dev": true
},
"web3": {
"version": "git+https://github.com/status-im/web3.js.git#17b13f26044e60ac824d1b97052bfad1be5af9cc",
"dev": true,
"requires": {
"bignumber.js": "git://github.com/status-im/bignumber.js.git#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"crypto-js": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
"utf8": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
"xhr2": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"xmlhttprequest": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz"
}
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xhr2": {
"version": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8=",
"dev": true
},
"xmlhttprequest": {
"version": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=",
"dev": true
}
}
}

51
_assets/static/package-lock.json generated Normal file
View File

@ -0,0 +1,51 @@
{
"name": "status-js",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"bignumber.js": {
"version": "github:status-im/bignumber.js#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"dev": true
},
"crypto-js": {
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
"integrity": "sha1-cV8HC/YBTyrpkqmLOSkli3E/CNU=",
"dev": true
},
"requirejs": {
"version": "2.3.5",
"resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz",
"integrity": "sha512-svnO+aNcR/an9Dpi44C7KSAy5fFGLtmPbaaCeQaklUz8BQhS64tWWIIlvEA5jrWICzlO/X9KSzSeXFnZdBu8nw==",
"dev": true
},
"utf8": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
"integrity": "sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY=",
"dev": true
},
"web3": {
"version": "git+https://github.com/status-im/web3.js.git#aca66029d7ffac8ed2803b2fc7f0fec01e335ca3",
"dev": true,
"requires": {
"bignumber.js": "github:status-im/bignumber.js#cc066a0a3d6bfe0c436c9957f4ea8344bf963c89",
"crypto-js": "3.1.8",
"utf8": "2.1.2",
"xhr2": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"xmlhttprequest": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz"
}
},
"xhr2": {
"version": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8=",
"dev": true
},
"xmlhttprequest": {
"version": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=",
"dev": true
}
}
}

View File

@ -1,28 +1,20 @@
{ {
"name": "status-js", "name": "status-js",
"version": "0.9.8", "version": "0.0.1",
"description": "JavaScript tests for RPC API (Whisper/5, Swarm)", "description": "Package file for NPM packages required by make generate, to be included in Go static assets",
"main": "index.js",
"engines": { "engines": {
"node": ">=8.9.0" "node": ">=8.9.0"
}, },
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"axios": "^0.17.1",
"chai": "^4.1.2",
"mocha": "^3.5.3",
"requirejs": "^2.3.4", "requirejs": "^2.3.4",
"rimraf": "^2.6.2",
"web3": "https://github.com/status-im/web3.js#status-develop" "web3": "https://github.com/status-im/web3.js#status-develop"
}, },
"scripts": {
"test": "mocha --bail --slow 1000 --full-trace static/tests"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/status-im/status-go.git" "url": "git+https://github.com/status-im/status-go.git"
}, },
"author": "Victor Farazdagi", "author": "Pedro Pombeiro",
"license": "ISC", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/status-im/status-go/issues" "url": "https://github.com/status-im/status-go/issues"

View File

@ -1,166 +0,0 @@
const crypto = require('crypto');
const { spawn } = require('child_process');
const { expect } = require('chai');
const axios = require('axios');
const rimraf = require('rimraf');
const Web3 = require('web3');
describe('Whisper MailServer', () => {
const topic = `0x${crypto.randomBytes(4).toString('hex')}`;
const sharedSymKey = '0x6c32583c0bc13ef90a10b36ed6f66baaa0e537d0677619993bfd72c819cba6f3';
const mailServerEnode = 'enode://b7e65e1bedc2499ee6cbd806945af5e7df0e59e4070c96821570bd581473eade24a489f5ec95d060c0db118c879403ab88d827d3766978f28708989d35474f87@127.0.0.1:8549';
const messageTTL = 5;
describe('Check prerequisites', () => {
console.log('Expecting MailServer running.')
console.log('./build/bin/statusd -les=false -shh -shh.mailserver -passwordfile=./static/keys/wnodepassword -http -httpport 8540 -listenaddr=127.0.0.1:8549 -identity=./static/keys/wnodekey')
it('MailServer should be running', () => {
const mailServer = new Web3(new Web3.providers.HttpProvider('http://localhost:8540'));
const version = mailServer.shh.version();
expect(version).to.equal("5.0");
});
});
describe('NodeA', () => {
let nodeA;
let nodeAProcess;
before((done) => {
nodeAProcess = spawn(
'./build/bin/statusd',
['-shh', '-les=false', '-datadir', 'wnode-data-1', '-http', '-httpport', '8590']
);
nodeA = new Web3(new Web3.providers.HttpProvider('http://localhost:8590'));
// need to wait a bit until the node is up and running
setTimeout(done, 500);
});
after((done) => {
nodeAProcess.kill('SIGTERM');
nodeAProcess.on('exit', (code, signal) => {
expect(code).to.be.null;
expect(signal).to.equal('SIGTERM');
rimraf('wnode-data-1', done);
});
});
it('Should add MailServer as a peer', (done) => {
// add MailServer as a peer
axios.post(nodeA.currentProvider.host, {
method: 'admin_addPeer',
params: [mailServerEnode],
id: 1
}).then((resp) => {
expect(resp.data.id).to.equal(1);
expect(resp.data.result).to.equal(true);
done();
}).catch(done);
})
it('Should send a message', (done) => {
const symKeyId = nodeA.shh.addSymKey(sharedSymKey);
const result = nodeA.shh.post({
symKeyID: symKeyId,
topic: topic,
payload: nodeA.toHex('hello!'),
ttl: messageTTL,
powTime: 10,
powTarget: 2.5
});
expect(result).to.be.true;
// give it some time to propagate before the node is shut down
setTimeout(done, 500);
});
});
describe('NodeB', () => {
let nodeBProcess;
let nodeB;
before((done) => {
nodeBProcess = spawn(
'./build/bin/statusd',
['-shh', '-les=false', '-datadir', 'wnode-data-2', '-http', '-httpport', '8591', '-log', 'INFO', '-logfile', 'wnode-data-2/wnode.log']
);
nodeB = new Web3(new Web3.providers.HttpProvider('http://localhost:8591'));
// need to wait a bit until the node is up and running
setTimeout(done, 500);
});
after((done) => {
nodeBProcess.kill('SIGTERM');
nodeBProcess.on('exit', (code, signal) => {
expect(code).to.be.null;
expect(signal).to.equal('SIGTERM');
rimraf('wnode-data-2', done);
});
});
it('Should add MailServer as a peer', (done) => {
// add MailServer as a peer
axios.post(nodeB.currentProvider.host, {
method: 'admin_addPeer',
params: [mailServerEnode],
id: 1
}).then((resp) => {
expect(resp.data.id).to.equal(1);
expect(resp.data.result).to.equal(true);
done();
}).catch(done);
})
it('Should request and receive old messages', (done) => {
const mailServerSymKeyID = nodeB.shh.generateSymKeyFromPassword('status-offline-inbox');
const symKeyId = nodeB.shh.addSymKey(sharedSymKey);
let requestedForMessages = false;
// wait until the message expires before setting up a filter
setTimeout(() => {
let counter = 0;
nodeB.shh.newMessageFilter({
topics: [topic],
symKeyID: symKeyId,
allowP2P: true
}, (err, data) => {
if (err) {
done(err);
return;
}
expect(nodeB.toAscii(data.payload)).to.equal('hello!');
if (requestedForMessages) {
done();
} else {
done('should not receive the message before requesting it');
}
}, done);
}, (messageTTL + 1) * 1000);
// request messages after the filter is set up and give it some addotional time
// so we are sure that the message was received after requesting it
setTimeout(() => {
// send a request for old messages
axios.post(nodeB.currentProvider.host, {
method: 'shh_requestMessages',
params: [{
mailServerPeer: mailServerEnode,
topic: topic,
symKeyID: mailServerSymKeyID
}],
id: 2
}).then((resp) => {
requestedForMessages = true;
expect(resp.data.id).to.equal(2);
expect(resp.data.result).to.equal(true);
}).catch(done);
}, (messageTTL + 5) * 1000);
});
});
});

View File

@ -1,754 +0,0 @@
var chai = require("chai");
var expect = chai.expect;
var assert = chai.assert;
var Web3 = require('web3');
describe.skip('Whisper Tests', function () {
var node1 = new Web3();
var node2 = new Web3();
var web3 = node1;
node1.setProvider(new web3.providers.HttpProvider('http://localhost:8645'));
node2.setProvider(new web3.providers.HttpProvider('http://localhost:8745'));
console.log('Node is expected: wnode-status -datadir app1 wnode -http -httpport 8645');
console.log('Node is expected: wnode-status -datadir app2 wnode -http -httpport 8745');
console.log('Node is expected: wnode-status -datadir wnode1 wnode -notify -injectaccounts=false -identity ./static/keys/wnodekey -firebaseauth ./static/keys/firebaseauthkey');
// some common vars
var topic1 = '0xdeadbeef'; // each topic 4 bytes, as hex
var topic2 = '0xbeefdead'; // each topic 4 bytes, as hex
var topic3 = '0xbebebebe'; // each topic 4 bytes, as hex
var topic4 = '0xdadadada'; // each topic 4 bytes, as hex
var identity1 = '0x04eedbaafd6adf4a9233a13e7b1c3c14461fffeba2e9054b8d456ce5f6ebeafadcbf3dce3716253fbc391277fa5a086b60b283daf61fb5b1f26895f456c2f31ae3';
var identity2 = '0x0490161b00f2c47542d28c2e8908e77159b1720dccceb6393d7c001850122efc3b1709bcea490fd8f5634ba1a145aa0722d86b9330b0e39a8d493cb981fd459da2';
// watchFilter makes sure that we halt the filter on first message received
var watchFilter = function (filter, done) {
var messageReceived = false;
filter.watch(function (error, message) {
if (messageReceived) return; // avoid double calling
messageReceived = true; // no need to watch for the filter any more
filter.stopWatching();
done(error, message);
});
};
// makeTopic generates random topic (4 bytes, in hex)
var makeTopic = function () {
var min = 1;
var max = Math.pow(16, 8);
var randInt = Math.floor(Math.random() * (max - min + 1)) + min;
return web3.toHex(randInt);
};
context('shh/5 API verification', function () {
it('statusd node is running', function () {
var web3 = new Web3();
var provider = new web3.providers.HttpProvider('http://localhost:8645');
var result = provider.send({});
assert.equal(typeof result, 'object');
});
it('shh.version()', function () {
var version = node1.shh.version();
assert.equal(version, '0x5', 'Whisper version does not match');
});
it('shh.info()', function () {
var info = node1.shh.info();
if (info == "") {
throw new Error('no Whisper info provided')
}
});
context('symmetric key management', function () {
var keyId = ''; // symmetric key ID (to be populated)
var keyVal = ''; // symmetric key value (to be populated)
it('shh.generateSymmetricKey()', function () {
keyId = node1.shh.generateSymmetricKey();
assert.lengthOf(keyId, 64, 'invalid keyId length');
});
it('shh.getSymmetricKey(keyId)', function () {
keyVal = node1.shh.getSymmetricKey(keyId);
assert.lengthOf(keyVal, 66, 'invalid key value length'); // 2 bytes for "0x"
});
it('shh.hasSymmetricKey(keyId)', function () {
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(true);
});
it('shh.deleteSymmetricKey(keyId)', function () {
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(true);
node1.shh.deleteSymmetricKey(keyId);
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(false);
});
it('shh.addSymmetricKeyDirect(keyVal)', function () {
keyIdOriginal = keyId;
keyId = node1.shh.addSymmetricKeyDirect(keyVal);
assert.notEqual(keyId, keyIdOriginal);
assert.lengthOf(keyId, 64, 'invalid keyId length');
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(true);
});
it('shh.addSymmetricKeyFromPassword(password)', function () {
var password = 'foobar';
var keyId = node1.shh.addSymmetricKeyFromPassword(password);
var keyVal = node1.shh.getSymmetricKey(keyId);
assert.lengthOf(keyId, 64, 'invalid keyId length');
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(true);
assert.equal(keyVal, '0xa582720d74d463589df14c11538189a1c07778c47e86f70bab7b5ba27e2de3cc');
});
});
context('assymmetric key management', function () {
var keyId = ''; // to be populated
var pubKey = ''; // to be populated
it('shh.newKeyPair()', function () {
keyId = node1.shh.newKeyPair();
assert.lengthOf(keyId, 64);
});
it('shh.hasKeyPair(id)', function () {
expect(node1.shh.hasKeyPair(keyId)).to.equal(true);
});
it('shh.getPublicKey(id)', function () {
pubKey = node1.shh.getPublicKey(keyId);
assert.lengthOf(pubKey, 132);
});
it('shh.hasKeyPair(pubKey)', function () {
expect(node1.shh.hasKeyPair(pubKey)).to.equal(true);
});
it('shh.getPrivateKey(id)', function () {
var prvkey = node1.shh.getPrivateKey(keyId);
assert.lengthOf(prvkey, 66);
});
it('shh.deleteKeyPair(id)', function () {
expect(node1.shh.hasKeyPair(pubKey)).to.equal(true);
expect(node1.shh.hasKeyPair(keyId)).to.equal(true);
node1.shh.deleteKeyPair(keyId);
expect(node1.shh.hasKeyPair(pubKey)).to.equal(false);
expect(node1.shh.hasKeyPair(keyId)).to.equal(false);
// re-create
keyId = node1.shh.newKeyPair();
assert.lengthOf(keyId, 64);
pubKey = node1.shh.getPublicKey(keyId);
assert.lengthOf(pubKey, 132);
});
it('shh.deleteKeyPair(pubKey)', function () {
expect(node1.shh.hasKeyPair(pubKey)).to.equal(true);
expect(node1.shh.hasKeyPair(keyId)).to.equal(true);
node1.shh.deleteKeyPair(pubKey);
expect(node1.shh.hasKeyPair(pubKey)).to.equal(false);
expect(node1.shh.hasKeyPair(keyId)).to.equal(false);
// re-create
keyId = node1.shh.newKeyPair();
assert.lengthOf(keyId, 64);
pubKey = node1.shh.getPublicKey(keyId);
assert.lengthOf(pubKey, 132);
});
});
context('subscribe and manually get messages', function () {
// NOTE: you can still use shh.filter to poll for messages automatically, see other examples
var filterid1 = ''; // sym filter, to be populated
var filterid2 = ''; // asym filter, to be populated
var keyId = ''; // symkey, to be populated
var uniqueTopic = makeTopic();
var payloadBeforeSymFilter = 'sent before filter was active (symmetric)';
var payloadAfterSymFilter = 'sent after filter was active (symmetric)';
var payloadBeforeAsymFilter = 'sent before filter was active (asymmetric)';
var payloadAfterAsymFilter = 'sent after filter was active (asymmetric)';
it('shh.subscribe(filterParams) - symmetric filter', function () {
keyId = node1.shh.generateSymmetricKey();
assert.lengthOf(keyId, 64);
// send message, which will be floating around *before* filter is even created
var message = {
type: "sym",
key: keyId,
topic: uniqueTopic,
payload: payloadBeforeSymFilter
};
expect(node1.shh.post(message)).to.equal(null);
// symmetric filter
filterid1 = node1.shh.subscribe({
type: "sym",
key: keyId,
sig: identity1,
topics: [topic1, topic2, uniqueTopic]
});
assert.lengthOf(filterid1, 64);
});
it('shh.subscribe(filterParams) - asymmetric filter', function () {
// send message, which will be floating around *before* filter is even created
var message = {
type: "asym",
key: identity2,
topic: uniqueTopic,
payload: payloadBeforeAsymFilter
};
expect(node1.shh.post(message)).to.equal(null);
// asymmetric filter
filterid2 = node1.shh.subscribe({
type: "asym",
key: identity2,
sig: identity1,
topics: [topic1, topic2, uniqueTopic]
});
assert.lengthOf(filterid1, 64);
});
it('shh.getFloatingMessages(filterID) - symmetric filter', function () {
// let's try to capture message that was there *before* filter is created
var messages = node1.shh.getFloatingMessages(filterid1);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 1);
assert.equal(web3.toAscii(messages[0].payload), payloadBeforeSymFilter);
// send message, after the filter has been already installed
var message = {
type: "sym",
key: keyId,
topic: uniqueTopic,
payload: payloadAfterSymFilter
};
expect(node1.shh.post(message)).to.equal(null);
});
it('shh.getFloatingMessages(filterID) - asymmetric filter', function () {
// let's try to capture message that was there *before* filter is created
var messages = node1.shh.getFloatingMessages(filterid2);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 1);
assert.equal(web3.toAscii(messages[0].payload), payloadBeforeAsymFilter);
// send message, after the filter has been already installed
var message = {
type: "asym",
key: identity2,
topic: uniqueTopic,
payload: payloadAfterAsymFilter
};
expect(node1.shh.post(message)).to.equal(null);
});
it('shh.getNewSubscriptionMessages(filterID) - symmetric filter', function (done) {
// allow some time for message to propagate
setTimeout(function () {
// now let's try to capture new messages from our last capture
var messages = node1.shh.getNewSubscriptionMessages(filterid1);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 1);
assert.equal(web3.toAscii(messages[0].payload), payloadAfterSymFilter);
// no more messages should be returned
messages = node1.shh.getNewSubscriptionMessages(filterid1);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 0);
done();
}, 200);
});
it('shh.getNewSubscriptionMessages(filterID) - asymmetric filter', function () {
// allow some time for message to propagate
setTimeout(function () {
// now let's try to capture new messages from our last capture
var messages = node1.shh.getNewSubscriptionMessages(filterid2);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 1);
assert.equal(web3.toAscii(messages[0].payload), payloadAfterAsymFilter);
// no more messages should be returned
messages = node1.shh.getNewSubscriptionMessages(filterid2);
assert.typeOf(messages, 'array');
assert.lengthOf(messages, 0);
done();
}, 200);
});
it.skip('shh.unsubscribe(filterID)', function () {
node1.shh.unsubscribe(filterid1);
node1.shh.unsubscribe(filterid2);
});
});
});
context('symmetrically encrypted messages send/recieve', function () {
this.timeout(0);
var keyId = ''; // symmetric key ID (to be populated)
var keyVal = ''; // symmetric key value (to be populated)
var payload = 'here come the dragons';
it('default test identity is present', function () {
if (!node1.shh.hasKeyPair(identity1)) {
throw new Error('identity not found in whisper: ' + identity1);
}
});
it('ensure symkey exists', function () {
keyId = node1.shh.generateSymmetricKey();
assert.lengthOf(keyId, 64);
expect(node1.shh.hasSymmetricKey(keyId)).to.equal(true);
});
it('read the generated symkey', function () {
keyVal = node1.shh.getSymmetricKey(keyId);
assert.lengthOf(keyVal, 66); // 2 bytes for "0x"
});
it('send/receive symmetrically encrypted message', function (done) {
// start watching for messages
watchFilter(node1.shh.filter({
type: "sym",
key: keyId,
sig: identity1,
topics: [topic1, topic2]
}), function (err, message) {
done(err);
});
// send message
var message = {
type: "sym",
key: keyId,
sig: identity1,
topic: topic1,
payload: web3.fromAscii(payload),
ttl: 20,
powTime: 2,
powTarget: 0.001
};
expect(node1.shh.post(message)).to.equal(null);
});
it('send the minimal symmetric message possible', function (done) {
var uniqueTopic = makeTopic();
// start watching for messages
watchFilter(node1.shh.filter({
type: "sym",
key: keyId,
topics: [uniqueTopic]
}), function (err, message) {
done(err);
});
// send message
var message = {
type: "sym",
key: keyId,
topic: uniqueTopic
};
expect(node1.shh.post(message)).to.equal(null);
});
});
context('message travelling from one node to another', function () {
this.timeout(0);
var keyId1 = ''; // symmetric key ID on node 1 (to be populated)
var keyId2 = ''; // symmetric key ID on node 2 (to be populated)
it('statusd node1 is running', function () {
var web3 = new Web3();
var provider = new web3.providers.HttpProvider('http://localhost:8645');
var result = provider.send({});
assert.equal(typeof result, 'object');
});
it('statusd node2 is running', function () {
var web3 = new Web3();
var provider = new web3.providers.HttpProvider('http://localhost:8745');
var result = provider.send({});
assert.equal(typeof result, 'object');
});
it('test identities injected', function () {
if (!node1.shh.hasKeyPair(identity1)) {
throw new Error('identity not found in whisper (node1): ' + identity1);
}
if (!node1.shh.hasKeyPair(identity2)) {
throw new Error('identity not found in whisper (node1): ' + identity2);
}
if (!node2.shh.hasKeyPair(identity1)) {
throw new Error('identity not found in whisper (node2): ' + identity1);
}
if (!node2.shh.hasKeyPair(identity2)) {
throw new Error('identity not found in whisper (node2): ' + identity2);
}
});
it('ensure symkey exists', function () {
keyId1 = node1.shh.generateSymmetricKey();
assert.lengthOf(keyId1, 64);
expect(node1.shh.hasSymmetricKey(keyId1)).to.equal(true);
// obtain key value
var keyVal = node1.shh.getSymmetricKey(keyId1);
assert.lengthOf(keyVal, 66); // 2 bytes of "0x"
// share the value with the node2
keyId2 = node2.shh.addSymmetricKeyDirect(keyVal);
assert.lengthOf(keyId2, 64);
expect(node2.shh.hasSymmetricKey(keyId2)).to.equal(true);
});
it('send symmetrically encrypted, signed message (node1 -> node2)', function (done) {
var payload = 'send symmetrically encrypted, signed message (node1 -> node2)';
var topic = makeTopic();
// start watching for messages
watchFilter(node2.shh.filter({
type: "sym",
sig: identity1,
key: keyId2,
topics: [topic]
}), function (err, message) {
done(err);
});
// send message
var message = {
type: "sym",
sig: identity1,
key: keyId1,
topic: topic,
payload: payload,
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
it('send asymmetrically encrypted, signed message (node1.id1 -> node2.id2)', function (done) {
var payload = 'send asymmetrically encrypted, signed message (node1.id1 -> node2.id2)';
var topic = makeTopic();
// start watching for messages
watchFilter(node2.shh.filter({
type: "asym",
sig: identity1,
key: identity2
}), function (err, message) {
done(err);
});
// send message
var message = {
type: "asym",
sig: identity1,
key: identity2,
topic: topic,
payload: payload,
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
});
context('push notifications', function () {
this.timeout(5000);
var discoveryPubKey = '0x040edb0d71a3dbe928e154fcb696ffbda359b153a90efc2b46f0043ce9f5dbe55b77b9328fd841a1db5273758624afadd5b39638d4c35b36b3a96e1a586c1b4c2a';
var discoverServerTopic = '0x268302f3'; // DISCOVER_NOTIFICATION_SERVER
var proposeServerTopic = '0x08e3d8c0'; // PROPOSE_NOTIFICATION_SERVER
var acceptServerTopic = '0x04f7dea6'; // ACCEPT_NOTIFICATION_SERVER
var ackClientSubscriptionTopic = '0x93dafe28'; // ACK_NOTIFICATION_SERVER_SUBSCRIPTION
var sendNotificationTopic = '0x69915296'; // SEND_NOTIFICATION
var newChatSessionTopic = '0x509579a2'; // NEW_CHAT_SESSION
var ackNewChatSessionTopic = '0xd012aae8'; // ACK_NEW_CHAT_SESSION
var newDeviceRegistrationTopic = '0x14621a51'; // NEW_DEVICE_REGISTRATION
var ackDeviceRegistrationTopic = '0x424358d6'; // ACK_DEVICE_REGISTRATION
var checkClientSessionTopic = '0x8745d931'; // CHECK_CLIENT_SESSION
var confirmClientSessionTopic = '0xd3202c5f'; // CONFIRM_CLIENT_SESSION
var dropClientSessionTopic = '0x3a6656bb'; // DROP_CLIENT_SESSION
// ensures that message had payload (which is HEX-encoded JSON)
var extractPayload = function (message) {
expect(message).to.have.property('payload');
return JSON.parse(web3.toAscii(message.payload));
};
var identity1 = ''; // pub key of device 1
var identity2 = ''; // pub key of device 2
var chatKeySharingTopic = makeTopic(); // topic used by device1 to send chat key to device 2
context('prepare devices', function () {
it('create key pair to be used as main identity on device1', function () {
var keyId = node1.shh.newKeyPair();
assert.lengthOf(keyId, 64);
identity1 = node1.shh.getPublicKey(keyId);
assert.lengthOf(identity1, 132);
expect(node1.shh.hasKeyPair(identity1)).to.equal(true);
expect(node1.shh.hasKeyPair(identity2)).to.equal(false);
});
it('create key pair to be used as main identity on device2', function () {
var keyId = node2.shh.newKeyPair();
assert.lengthOf(keyId, 64);
identity2 = node2.shh.getPublicKey(keyId);
assert.lengthOf(identity1, 132);
expect(node2.shh.hasKeyPair(identity1)).to.equal(false);
expect(node2.shh.hasKeyPair(identity2)).to.equal(true);
});
});
context('run device1', function () {
var serverId = ''; // accepted/selected server id
var subscriptionKeyId = ''; // symkey provided by server, and used to configure client-server subscription
var chatKeyId = ''; // symkey provided by server, and shared among clients so that they can trigger notifications
var appChatId = ''; // chat id that identifies device1-device2 interaction session on RN app level
it('start discovery by sending discovery request', function () {
var message = {
type: "asym",
sig: identity1,
key: discoveryPubKey,
topic: discoverServerTopic,
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
it('watch for server proposals', function (done) {
watchFilter(node1.shh.filter({
type: "asym",
sig: discoveryPubKey,
key: identity1,
topics: [proposeServerTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('server');
serverId = payload.server;
done();
});
});
it('client accepts server', function () {
var message = {
type: "asym",
sig: identity1,
key: discoveryPubKey,
topic: acceptServerTopic,
payload: '{"server": "' + serverId + '"}',
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
it('watch for server ACK response and save provided subscription key', function (done) {
watchFilter(node1.shh.filter({
type: "asym",
key: identity1,
topics: [ackClientSubscriptionTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('server');
expect(payload).to.have.property('key');
// save subscription key
subscriptionKeyId = node1.shh.addSymmetricKeyDirect(payload.key);
assert.lengthOf(subscriptionKeyId, 64);
expect(node1.shh.hasSymmetricKey(subscriptionKeyId)).to.equal(true);
done();
});
});
it('create chat session', function () {
appChatId = makeTopic(); // globally unique chat id
var message = {
type: "sym",
sig: identity1,
key: subscriptionKeyId,
topic: newChatSessionTopic,
payload: '{"chat": "' + appChatId + '"}',
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
it('watch for server to respond with chat key', function (done) {
watchFilter(node1.shh.filter({
type: "asym",
key: identity1,
topics: [ackNewChatSessionTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('server');
expect(payload).to.have.property('key');
// save subscription key
chatKeyId = node1.shh.addSymmetricKeyDirect(payload.key);
assert.lengthOf(chatKeyId, 64);
expect(node1.shh.hasSymmetricKey(chatKeyId)).to.equal(true);
done();
});
});
it('register device with a given chat', function (done) {
// this obtained from https://status-sandbox-c1b34.firebaseapp.com/
var deviceId = 'ca5pRJc6L8s:APA91bHpYFtpxvXx6uOayGmnNVnktA4PEEZdquCCt3fWR5ldLzSy1A37Tsbzk5Gavlmk1d_fvHRVnK7xPAhFFl-erF7O87DnIEstW6DEyhyiKZYA4dXFh6uy323f9A3uw5hEtT_kQVhT';
var message = {
type: "sym",
sig: identity1,
key: chatKeyId,
topic: newDeviceRegistrationTopic,
payload: '{"device": "' + deviceId + '"}',
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
// watch for server server ACK
watchFilter(node1.shh.filter({
type: "asym",
key: identity1,
topics: [ackDeviceRegistrationTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('server');
done();
});
});
it('share chat key, so that another device can send us notifications', function () {
var chatKey = node1.shh.getSymmetricKey(chatKeyId);
assert.lengthOf(chatKey, 66);
var message = {
type: "asym",
sig: identity1,
key: identity2,
topic: chatKeySharingTopic,
payload: '{"chat": "' + appChatId + '", "key": "' + chatKey + '"}',
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
});
context('run device2', function () {
var chatKeyId = '';
it('watch for device1 to send us chat key', function (done) {
watchFilter(node2.shh.filter({
type: "asym",
key: identity2,
topics: [chatKeySharingTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('chat');
expect(payload).to.have.property('key');
// persist chat key
chatKeyId = node2.shh.addSymmetricKeyDirect(payload.key);
assert.lengthOf(chatKeyId, 64);
expect(node2.shh.hasSymmetricKey(chatKeyId)).to.equal(true);
done();
});
});
it('trigger notification (from device2, on device1)', function () {
var message = {
type: "sym",
sig: identity2,
key: chatKeyId,
topic: sendNotificationTopic,
payload: '{' // see https://firebase.google.com/docs/cloud-messaging/http-server-ref
+ '"notification": {'
+ '"title": "status.im notification",'
+ '"body": "Hello this is test notification!",'
+ '"icon": "https://status.im/img/logo.png",'
+ '"click_action": "https://status.im"'
+ '},'
+ '"to": "{{ ID }}"' // this get replaced by device id your've registered
+ '}',
ttl: 20
};
expect(node2.shh.post(message)).to.equal(null);
});
});
context('misc methods and cleanup', function () {
it('check client session', function (done) {
// request status
var message = {
type: "asym",
sig: identity1,
key: discoveryPubKey,
topic: checkClientSessionTopic,
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
// process server's response
watchFilter(node1.shh.filter({
type: "asym",
key: identity1,
topics: [confirmClientSessionTopic]
}), function (err, message) {
if (err) return done(err);
// process payload
var payload = extractPayload(message);
expect(payload).to.have.property('server');
expect(payload).to.have.property('key');
done();
});
});
it('remove client session', function () {
var message = {
type: "asym",
sig: identity1,
key: discoveryPubKey,
topic: dropClientSessionTopic,
ttl: 20
};
expect(node1.shh.post(message)).to.equal(null);
});
});
});
});