From bbfdd1273556766d77c9d87444b1fac90d02cdb7 Mon Sep 17 00:00:00 2001 From: hh Date: Tue, 16 Mar 2021 20:17:22 +0800 Subject: [PATCH] move to test fixture, auto create out --- test/fixture/autoCompile.ts | 23 +- .../desc/p2pkh_desc_missing_version.json | 36 +++ .../desc/p2pkh_desc_without_sourceMap.json | 40 +++ test/fixture/desc/version_1.json | 36 +++ test/fixture/desc/version_2.json | 238 ++++++++++++++++++ 5 files changed, 370 insertions(+), 3 deletions(-) create mode 100644 test/fixture/desc/p2pkh_desc_missing_version.json create mode 100644 test/fixture/desc/p2pkh_desc_without_sourceMap.json create mode 100644 test/fixture/desc/version_1.json create mode 100644 test/fixture/desc/version_2.json diff --git a/test/fixture/autoCompile.ts b/test/fixture/autoCompile.ts index 0b87eb67..ff25fddd 100644 --- a/test/fixture/autoCompile.ts +++ b/test/fixture/autoCompile.ts @@ -1,13 +1,19 @@ import glob = require('glob'); -import { join } from 'path'; +import { basename, join } from 'path'; import { compileContract } from '../../src/utils'; import { exit } from 'process'; +import { copyFileSync, existsSync,mkdirSync } from 'fs'; function compileAllContracts() { + + const out = join(__dirname, "..", "..", "out"); + if(!existsSync(out)) { + mkdirSync(out); + } const contracts = glob.sync(join(__dirname, './*.scrypt')); contracts.forEach(filePath => { - const result = compileContract(filePath, join(__dirname, "..", "..", "out")); + const result = compileContract(filePath, out); if (result.errors.length > 0) { console.log(`Contract ${filePath} compiling failed with errors:`); @@ -17,4 +23,15 @@ function compileAllContracts() { }) } -compileAllContracts(); \ No newline at end of file + +function copyDescFiles() { + const descs = glob.sync(join(__dirname, 'desc', './*.json')); + descs.forEach(filePath => { + copyFileSync(filePath, join(__dirname, '..', '..', 'out', basename(filePath))) + }) +} + + +compileAllContracts(); + +copyDescFiles(); \ No newline at end of file diff --git a/test/fixture/desc/p2pkh_desc_missing_version.json b/test/fixture/desc/p2pkh_desc_missing_version.json new file mode 100644 index 00000000..b1acc727 --- /dev/null +++ b/test/fixture/desc/p2pkh_desc_missing_version.json @@ -0,0 +1,36 @@ +{ + "compilerVersion": "0.2.12+commit.ce592f4", + "contract": "DemoP2PKH", + "md5": "35bbeee99481c17c95f580e8b86d117f", + "structs": [], + "abi": [ + { + "type": "function", + "name": "unlock", + "index": 0, + "params": [ + { + "name": "sig", + "type": "Sig" + }, + { + "name": "pubKey", + "type": "PubKey" + } + ] + }, + { + "type": "constructor", + "params": [ + { + "name": "pubKeyHash", + "type": "Ripemd160" + } + ] + } + ], + "file": "", + "asm": "OP_NOP OP_0 $pubKeyHash OP_0 OP_PICK OP_2 OP_ROLL OP_DROP OP_1 OP_ROLL OP_DROP OP_NOP OP_1 OP_PICK OP_HASH160 OP_1 OP_PICK OP_EQUAL OP_VERIFY OP_2 OP_PICK OP_2 OP_PICK OP_CHECKSIG OP_NIP OP_NIP OP_NIP", + "sources": [], + "sourceMap": [] +} \ No newline at end of file diff --git a/test/fixture/desc/p2pkh_desc_without_sourceMap.json b/test/fixture/desc/p2pkh_desc_without_sourceMap.json new file mode 100644 index 00000000..eeb7647d --- /dev/null +++ b/test/fixture/desc/p2pkh_desc_without_sourceMap.json @@ -0,0 +1,40 @@ +{ + "version": 2, + "compilerVersion": "0.2.12+commit.ce592f4", + "contract": "DemoP2PKH", + "md5": "35bbeee99481c17c95f580e8b86d117f", + "structs": [], + "abi": [ + { + "type": "function", + "name": "unlock", + "index": 0, + "params": [ + { + "name": "sig", + "type": "Sig", + "finalType": "Sig" + }, + { + "name": "pubKey", + "type": "PubKey", + "finalType": "PubKey" + } + ] + }, + { + "type": "constructor", + "params": [ + { + "name": "pubKeyHash", + "type": "Ripemd160", + "finalType": "Ripemd160" + } + ] + } + ], + "file": "", + "asm": "OP_NOP OP_0 $pubKeyHash OP_0 OP_PICK OP_2 OP_ROLL OP_DROP OP_1 OP_ROLL OP_DROP OP_NOP OP_1 OP_PICK OP_HASH160 OP_1 OP_PICK OP_EQUAL OP_VERIFY OP_2 OP_PICK OP_2 OP_PICK OP_CHECKSIG OP_NIP OP_NIP OP_NIP", + "sources": [], + "sourceMap": [] +} \ No newline at end of file diff --git a/test/fixture/desc/version_1.json b/test/fixture/desc/version_1.json new file mode 100644 index 00000000..8f917ab8 --- /dev/null +++ b/test/fixture/desc/version_1.json @@ -0,0 +1,36 @@ +{ + "version": 1, + "compilerVersion": "0.2.12+commit.ce592f4", + "contract": "DemoP2PKH", + "md5": "35bbeee99481c17c95f580e8b86d117f", + "abi": [ + { + "type": "function", + "name": "unlock", + "index": 0, + "params": [ + { + "name": "sig", + "type": "Sig" + }, + { + "name": "pubKey", + "type": "PubKey" + } + ] + }, + { + "type": "constructor", + "params": [ + { + "name": "pubKeyHash", + "type": "Ripemd160" + } + ] + } + ], + "file": "", + "asm": "OP_NOP OP_0 $pubKeyHash OP_0 OP_PICK OP_2 OP_ROLL OP_DROP OP_1 OP_ROLL OP_DROP OP_NOP OP_1 OP_PICK OP_HASH160 OP_1 OP_PICK OP_EQUAL OP_VERIFY OP_2 OP_PICK OP_2 OP_PICK OP_CHECKSIG OP_NIP OP_NIP OP_NIP", + "sources": [], + "sourceMap": [] +} \ No newline at end of file diff --git a/test/fixture/desc/version_2.json b/test/fixture/desc/version_2.json new file mode 100644 index 00000000..8fc9bb16 --- /dev/null +++ b/test/fixture/desc/version_2.json @@ -0,0 +1,238 @@ +{ + "version": 2, + "compilerVersion": "0.3.2+commit.eb5b607", + "contract": "Alias", + "md5": "2bc293c855fbd6d6924a76c6e6e56337", + "structs": [ + { + "name": "Person", + "params": [ + { + "name": "age", + "type": "Age", + "finalType": "int" + }, + { + "name": "name", + "type": "Name", + "finalType": "bytes" + }, + { + "name": "token", + "type": "Token", + "finalType": "int" + } + ] + }, + { + "name": "Block", + "params": [ + { + "name": "height", + "type": "Height", + "finalType": "int" + }, + { + "name": "time", + "type": "Time", + "finalType": "int" + }, + { + "name": "coinbase", + "type": "Coinbase", + "finalType": "bytes" + } + ] + } + ], + "alias": [ + { + "name": "Male", + "type": "Person" + }, + { + "name": "Female", + "type": "Person" + }, + { + "name": "Integer", + "type": "int" + }, + { + "name": "Name", + "type": "bytes" + }, + { + "name": "Age", + "type": "Integer" + }, + { + "name": "Token", + "type": "Integer" + }, + { + "name": "Tokens", + "type": "Token[3]" + }, + { + "name": "Coinbase", + "type": "bytes" + }, + { + "name": "Time", + "type": "int" + }, + { + "name": "Height", + "type": "int" + }, + { + "name": "MaleAAA", + "type": "Male" + } + ], + "abi": [ + { + "type": "function", + "name": "unlock", + "index": 0, + "params": [ + { + "name": "bob", + "type": "MaleAAA", + "finalType": "struct Person {}" + } + ] + }, + { + "type": "function", + "name": "setToken", + "index": 1, + "params": [ + { + "name": "tokens", + "type": "Tokens", + "finalType": "int[3]" + } + ] + }, + { + "type": "constructor", + "params": [ + { + "name": "person", + "type": "Female", + "finalType": "struct Person {}" + } + ] + } + ], + "file": "file:///C:/Users/myland/code/scryptlib/test/fixture/alias.scrypt", + "asm": "OP_NOP OP_0 OP_0 OP_0 $person.age $person.name $person.token OP_2 OP_PICK OP_2 OP_PICK OP_2 OP_PICK OP_8 OP_ROLL OP_8 OP_ROLL OP_8 OP_ROLL OP_DROP OP_DROP OP_DROP OP_5 OP_ROLL OP_5 OP_ROLL OP_5 OP_ROLL OP_DROP OP_DROP OP_DROP OP_NOP OP_3 OP_PICK OP_0 OP_EQUAL OP_IF OP_6 OP_PICK OP_3 OP_PICK OP_1 OP_PICK OP_1 OP_PICK OP_ADD OP_10 OP_GREATERTHAN OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_ELSE OP_3 OP_PICK OP_1 OP_EQUAL OP_IF OP_6 OP_0 OP_DUP OP_0 OP_GREATERTHANOREQUAL OP_VERIFY OP_DUP OP_3 OP_LESSTHAN OP_VERIFY OP_1 OP_MUL OP_SUB OP_TOALTSTACK OP_FROMALTSTACK OP_DUP OP_TOALTSTACK OP_PICK OP_FROMALTSTACK OP_DROP OP_1 OP_ROLL OP_DROP OP_0 OP_PICK OP_10 OP_NUMEQUAL OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_NIP OP_ELSE OP_0 OP_ENDIF OP_ENDIF", + "sources": [ + "C:\\Users\\myland\\code\\scryptlib\\test\\fixture\\alias.scrypt" + ], + "sourceMap": [ + "-1:1:1:1:1#Alias.constructor:0", + "0:29:3:29:15", + "0:29:3:29:15", + "0:29:3:29:15", + "0:31:15:31:28", + "0:31:15:31:28", + "0:31:15:31:28", + "0:32:18:32:24", + "0:32:18:32:24", + "0:32:18:32:24", + "0:32:18:32:24", + "0:32:18:32:24", + "0:32:18:32:24", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "0:32:5:32:16", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1#Alias.constructor:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "0:38:20:38:27", + "0:38:20:38:27", + "0:39:18:39:32", + "0:39:18:39:32", + "0:41:13:41:21", + "0:41:13:41:21", + "0:41:24:41:30", + "0:41:24:41:30", + "0:41:13:41:30", + "0:41:33:41:35", + "0:41:13:41:35", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "0:46:24:46:30", + "0:46:31:46:32", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:24:46:30", + "0:46:5:46:22", + "0:46:5:46:22", + "0:46:5:46:22", + "0:47:13:47:30", + "0:47:13:47:30", + "0:47:33:47:35", + "0:47:13:47:35", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1", + "-1:1:1:1:1" + ] +} \ No newline at end of file