-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
{ | ||
"name": "fxchain", | ||
"version": "0.1.0", | ||
"description": "The best blockchain in the world.", | ||
"main": "src/index.ts", | ||
"repository": "[email protected]:fgladisch/fxchain.git", | ||
"author": "Felix Gladisch <[email protected]>", | ||
"license": "MIT", | ||
"private": false, | ||
"devDependencies": { | ||
"@types/node": "^9.6.0", | ||
"tslint": "5.9.1", | ||
"tslint-config-prettier": "^1.10.0", | ||
"typescript": "2.7.2" | ||
}, | ||
"scripts": { | ||
"compile": "tsc" | ||
}, | ||
"engines": { | ||
"node": "^8 || ^9" | ||
} | ||
"name": "fxchain", | ||
"version": "0.1.0", | ||
"description": "The best blockchain in the world.", | ||
"main": "src/index.ts", | ||
"repository": "[email protected]:fgladisch/fxchain.git", | ||
"author": "Felix Gladisch <[email protected]>", | ||
"license": "MIT", | ||
"private": false, | ||
"devDependencies": { | ||
"@types/chai": "4.1.2", | ||
"@types/mocha": "5.0.0", | ||
"@types/node": "9.6.0", | ||
"chai": "4.1.2", | ||
"mocha": "5.0.5", | ||
"ts-node": "5.0.1", | ||
"tslint": "5.9.1", | ||
"tslint-config-prettier": "1.10.0", | ||
"typescript": "2.7.2" | ||
}, | ||
"scripts": { | ||
"compile": "tsc", | ||
"test": "mocha -r ts-node/register src/**/*.test.ts" | ||
}, | ||
"engines": { | ||
"node": "8 || 9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { assert } from "chai"; | ||
|
||
import { Block } from "./block.model"; | ||
import { Blockchain } from "./blockchain.model"; | ||
|
||
const TEST_DATA: string = "TEST"; | ||
|
||
describe("Blockchain", () => { | ||
it("should create a new blockchain", () => { | ||
const blockchain: Blockchain = new Blockchain(); | ||
assert.isDefined(blockchain.getGenesisBlock()); | ||
}); | ||
|
||
it("should create a blockchain with existing blocks", () => { | ||
const testBlock: Block = new Block({ | ||
data: TEST_DATA, | ||
index: 0, | ||
previousHash: null | ||
}); | ||
const blockchain: Blockchain = new Blockchain([testBlock]); | ||
assert.equal(blockchain.getChain()[0], testBlock); | ||
}); | ||
|
||
it("should generate a new block", () => { | ||
const blockchain: Blockchain = new Blockchain(); | ||
blockchain.generateNextBlock(TEST_DATA); | ||
const latestBlock: Block = blockchain.getLatestBlock(); | ||
assert.equal(latestBlock.data, TEST_DATA); | ||
}); | ||
|
||
it("should overwrite the existing chain", () => { | ||
const blockchain: Blockchain = new Blockchain(); | ||
blockchain.generateNextBlock(TEST_DATA); | ||
const copy: Blockchain = new Blockchain([...blockchain.getChain()]); | ||
copy.generateNextBlock(TEST_DATA); | ||
assert.lengthOf(blockchain.getChain(), 2); | ||
blockchain.replaceChain(copy.getChain()); | ||
assert.lengthOf(blockchain.getChain(), 3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.