OSDN Git Service

Merge pull request #3 from Bytom/dev
[bytom/bytom-node-sdk.git] / test / block.js
diff --git a/test/block.js b/test/block.js
new file mode 100644 (file)
index 0000000..9155e7a
--- /dev/null
@@ -0,0 +1,87 @@
+/* eslint-env mocha */
+
+const chai = require('chai')
+const chaiAsPromised = require('chai-as-promised')
+chai.use(chaiAsPromised)
+const expect = chai.expect
+
+const {
+  client
+} = require('./testHelpers')
+
+describe('Block', () => {
+
+  describe('block count', () => {
+    it('simple example', () =>
+      client.block.getBlockCount()
+        .then(items =>
+          expect(items.block_count).not.to.be.empty
+        )
+    )
+  })
+
+  describe('block hash', () => {
+    it('simple example', () => {
+      return client.block.getBlockHash()
+        .then((resp) => {
+          expect(resp.block_hash).not.to.be.empty
+        })
+    })
+  })
+
+  describe('get Block', () => {
+    it('simple example', () => {
+      let blockHash
+      return client.block.getBlockHash()
+        .then((resp) => {
+          blockHash = resp.block_hash
+          return client.block.getBlock({block_hash: resp.block_hash})
+        })
+        .then((resp) =>
+          expect(resp.hash).to.equal(blockHash)
+        )
+    })
+  })
+
+  describe('get Block Header', () => {
+    it('simple example', () => {
+      let blockHash
+      return client.block.getBlockHash()
+        .then((resp) => {
+          blockHash = resp.block_hash
+          return client.block.getBlockHeader({block_hash: resp.block_hash})
+        })
+        .then((resp) =>
+          expect(resp.block_header).not.to.be.empty
+        )
+    })
+  })
+
+  describe('get Difficulty', () => {
+    it('simple example', () => {
+      let blockHash
+      return client.block.getBlockHash()
+        .then((resp) => {
+          blockHash = resp.block_hash
+          return client.block.getDifficulty({block_hash: resp.block_hash})
+        })
+        .then((resp) =>
+          expect(resp.hash).to.equal(blockHash)
+        )
+    })
+  })
+
+  describe('get Hash Rate', () => {
+    it('simple example', () => {
+      let blockHash
+      return client.block.getBlockHash()
+        .then((resp) => {
+          blockHash = resp.block_hash
+          return client.block.getHashRate({block_hash: resp.block_hash})
+        })
+        .then((resp) =>
+          expect(resp.hash).to.equal(blockHash)
+        )
+    })
+  })
+})
\ No newline at end of file