1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 01:48:17 +00:00

Adding emscripten tests

This commit is contained in:
Karel Bilek 2017-03-31 01:35:00 +02:00 committed by Pavol Rusnak
parent e15a7bc986
commit 81c61ba5a4
7 changed files with 1051 additions and 9 deletions

View File

@ -1,7 +1,10 @@
sudo: false sudo: required
dist: trusty dist: trusty
language: c language: c
services:
- docker
addons: addons:
apt: apt:
sources: sources:
@ -13,6 +16,7 @@ addons:
- cmake-data - cmake-data
- libssl-dev - libssl-dev
- python-pip - python-pip
- nodejs
install: install:
- pip install --user pytest ecdsa curve25519-donna - pip install --user pytest ecdsa curve25519-donna
@ -26,3 +30,4 @@ script:
- mkdir _build && cd _build - mkdir _build && cd _build
- cmake .. - cmake ..
- make - make
- cd .. && cd emscripten && rm trezor-crypto.js && make docker-build && make test-correctness

View File

@ -1,2 +1,3 @@
node_modules/ node_modules/
benchmark-browserify.js
test-browserify.js test-browserify.js

View File

@ -8,24 +8,30 @@ EMFLAGS = \
SRC = ../bignum.c ../ecdsa.c ../secp256k1.c ../hmac.c ../bip32.c \ SRC = ../bignum.c ../ecdsa.c ../secp256k1.c ../hmac.c ../bip32.c \
../base58.c ../ripemd160.c ../sha2.c ../rand.c ../address.c ../base58.c ../ripemd160.c ../sha2.c ../rand.c ../address.c
all: trezor-crypto.js test-browserify.js all: trezor-crypto.js benchmark-browserify.js
trezor-crypto.js: $(SRC) trezor-crypto.js: $(SRC)
emcc $(EMFLAGS) -o $@ $^ emcc $(EMFLAGS) -o $@ $^
test-browserify.js: node_modules trezor-crypto.js test.js benchmark-browserify.js: node_modules trezor-crypto.js benchmark.js
$(shell npm bin)/browserify test.js -o $@ --noparse=`pwd`/trezor-crypto.js $(shell npm bin)/browserify benchmark.js -o $@ --noparse=`pwd`/trezor-crypto.js
@echo "open test.html in your favourite browser" @echo "open benchmark.html in your favourite browser"
test-node: node_modules trezor-crypto.js test.js benchmark-node: node_modules trezor-crypto.js benchmark.js
node test.js node benchmark.js
node_modules: node_modules:
npm install npm install
npm install browserify npm install browserify
clean: clean:
rm -f trezor-crypto.js test-browserify.js rm -f trezor-crypto.js benchmark-browserify.js
docker: docker:
docker run --rm -i -v $(shell pwd)/..:/src -t apiaryio/emcc /bin/bash docker run --rm -i -v $(shell pwd)/..:/src -t apiaryio/emcc /bin/bash
docker-build:
docker run --rm -v $(shell pwd)/..:/src apiaryio/emcc /bin/bash -c 'cd emscripten && make'
test-correctness: node_modules
node test-correctness.js

View File

@ -3,6 +3,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body> <body>
<script async src="test-browserify.js"></script> <script async src="benchmark-browserify.js"></script>
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
var crypto = require('./trezor-crypto');
var bitcoin = require('bitcoinjs-lib');
var XPUB =
'xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy';
var node = bitcoin.HDNode.fromBase58(XPUB).derive(0);
var nodeStruct = {
depth: node.depth,
child_num: node.index,
fingerprint: node.parentFingerprint,
chain_code: node.chainCode,
public_key: node.keyPair.getPublicKeyBuffer()
};
var addresses = crypto.deriveAddressRange(nodeStruct, 0, 999, 0);
var fs = require('fs');
var loaded = fs.readFileSync('test-addresses.txt').toString().split("\n");
for (var i = 0; i < 1000; i++) {
if (loaded[i] !== addresses[i]) {
console.log("bad address", i);
process.exit(1)
}
}
console.log("Testing address ended correctly");
process.exit(0)