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
language: c
services:
- docker
addons:
apt:
sources:
@ -13,6 +16,7 @@ addons:
- cmake-data
- libssl-dev
- python-pip
- nodejs
install:
- pip install --user pytest ecdsa curve25519-donna
@ -26,3 +30,4 @@ script:
- mkdir _build && cd _build
- cmake ..
- make
- cd .. && cd emscripten && rm trezor-crypto.js && make docker-build && make test-correctness

View File

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

View File

@ -8,24 +8,30 @@ EMFLAGS = \
SRC = ../bignum.c ../ecdsa.c ../secp256k1.c ../hmac.c ../bip32.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)
emcc $(EMFLAGS) -o $@ $^
test-browserify.js: node_modules trezor-crypto.js test.js
$(shell npm bin)/browserify test.js -o $@ --noparse=`pwd`/trezor-crypto.js
@echo "open test.html in your favourite browser"
benchmark-browserify.js: node_modules trezor-crypto.js benchmark.js
$(shell npm bin)/browserify benchmark.js -o $@ --noparse=`pwd`/trezor-crypto.js
@echo "open benchmark.html in your favourite browser"
test-node: node_modules trezor-crypto.js test.js
node test.js
benchmark-node: node_modules trezor-crypto.js benchmark.js
node benchmark.js
node_modules:
npm install
npm install browserify
clean:
rm -f trezor-crypto.js test-browserify.js
rm -f trezor-crypto.js benchmark-browserify.js
docker:
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">
</head>
<body>
<script async src="test-browserify.js"></script>
<script async src="benchmark-browserify.js"></script>
</body>
</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)