ethereumjs-account/test/index.js

const Account = require('../index.js')
const tape = require('tape') tape('empty constructor', function (tester) {
var it = tester.test
it('should work', function (t) {
var account = new Account() //创建一个空账户
t.equal(account.nonce.toString('hex'), '')
t.equal(account.balance.toString('hex'), '')
t.equal(account.stateRoot.toString('hex'), '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421') //即null的RLP编码的Keccak-256 hash值,ethUtil.SHA3_RLP_S,现在更名为KECCAK256_RLP_S
t.equal(account.codeHash.toString('hex'), 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470') //即空字符串hash值,ethUtil.SHA3_NULL_S
t.end()
})
}) tape('constructor with Array', function (tester) {
var it = tester.test
it('should work', function (t) {
var raw = [ //数组的格式初始化
'0x02', // nonce
'0x0384', // balance
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', // stateRoot,是null的RLP编码的Keccak-256 hash值
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' // codeHash,是空字符串hash值
]
var account = new Account(raw)
t.equal(account.nonce.toString('hex'), '')
t.equal(account.balance.toString('hex'), '')
t.equal(account.stateRoot.toString('hex'), '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421')
t.equal(account.codeHash.toString('hex'), 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.end()
})
}) tape('constructor with Object', function (tester) {
var it = tester.test
it('should work', function (t) {
var raw = { //对象的格式初始化
nonce: '0x02',
balance: '0x0384',
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',// stateRoot,是null的RLP编码的Keccak-256 hash值
codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' // codeHash,是空字符串hash值
}
var account = new Account(raw)
t.equal(account.nonce.toString('hex'), '')
t.equal(account.balance.toString('hex'), '')
t.equal(account.stateRoot.toString('hex'), '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421')
t.equal(account.codeHash.toString('hex'), 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.end()
})
}) tape('constructor with RLP', function (tester) {
var it = tester.test
it('should work', function (t) {//RLP的格式初始化
var account = new Account('f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.equal(account.nonce.toString('hex'), '')
t.equal(account.balance.toString('hex'), '')
t.equal(account.stateRoot.toString('hex'), '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421')
t.equal(account.codeHash.toString('hex'), 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.end()
})
}) tape('serialize', function (tester) {
var it = tester.test
it('should work', function (t) {//account.serialize()得到的就是RLP的值
var account = new Account('f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.equal(account.serialize().toString('hex'), 'f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.end()
})
}) tape('isContract', function (tester) {
var it = tester.test
it('should return false', function (t) {
var account = new Account('f84602820384a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
t.equal(account.isContract(), false)//这个不是合约账户,因为codeHash为空字符串hash值
t.end()
})
it('should return true', function (t) {
var raw = {
nonce: '0x01',
balance: '0x0042',
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
codeHash: '0xc5d2461236f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'//不是空字符串hash值了
}
var account = new Account(raw)
t.equal(account.isContract(), true)//所以就是合约账户了
t.end()
})
})

ethereumjs/ethereumjs-account-2-test的更多相关文章

  1. ethereumjs/ethereumjs-util

    ethereumjs/ethereumjs-util Most of the string manipulation methods are provided by ethjs-util 更多的字符串 ...

  2. ethereumjs/ethereumjs-wallet

    Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...

  3. ethereumjs/ethereumjs-tx

    https://github.com/ethereumjs/ethereumjs-tx A simple module for creating, manipulating and signing e ...

  4. ethereumjs/ethereumjs-vm-3-StateManager

    https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/stateManager.md StateManager 要与本博客的ethe ...

  5. ethereumjs/ethereumjs-vm-2-API文档

    https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/index.md vm.runBlockchain Processes blo ...

  6. ethereumjs/ethereumjs-vm-4-tests

    根据代码发现还要了解的模块有: ethereumjs/merkle-patricia-tree -对应数据存储的数据结构 ethereumjs-blockchain —— 区块链 ethereumjs ...

  7. ethereumjs/merkle-patricia-tree-1-简介

    https://github.com/ethereumjs/merkle-patricia-tree SYNOPSIS概要 This is an implementation of the modif ...

  8. ethereumjs/ethereumjs-account-1-简介和API

    https://github.com/ethereumjs/ethereumjs-account Encoding, decoding and validation of Ethereum's Acc ...

  9. ethereumjs/ethereumjs-icap

    https://github.com/ethereumjs/ethereumjs-icap ethereumjs-icap 安装: npm install ethereumjs-icap --save ...

  10. ethereumjs/ethereumjs-common-1-简介

    为了了解ethereumjs/ethereumjs-block-3-代码的使用需要了解的一个模块 https://github.com/ethereumjs/ethereumjs-common Com ...

随机推荐

  1. django(六):view和cbv

    FBV即以函数的形式实现视图函数,CBV即以类的形式实现视图函数:相比而言,CBV根据请求方式书写各自的代码逻辑,结构清晰明了,但是由于多了一层反射机制,性能要差一些:FBV执行效率要高一些,但是代码 ...

  2. OracleServer总结进阶之系统分析(进阶完结)

    个人原创,转载请在文章头部明显位置注明出处:https://www.cnblogs.com/sunshine5683/p/10080102.html 在上一篇进阶中大概讲解了一些关于进阶方面的知识,今 ...

  3. NTP POOL PROJECT:全球最大的免费NTP服务集群

    pool.ntp.org项目是一个提供可靠易用的NTP服务的虚拟集群,它作为一个大的NP服务器可以支撑全球数百万客户端使用.该项目允许那些能提供NTP服务的服务器加入到该集群中,截止2012年8月份, ...

  4. leaflet 整合 esri

    此 demo 通过 proj4js 将 leaflet 与 esri 整合起来,同时添加了 ClusteredFeatureLayer 的支持. 下载 <html> <head> ...

  5. Spring Boot—19Session

    pom.xm <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  6. ifup / ifdown eth0 / eno1 reports unknown interface when it exists!

    li {list-style-type:decimal;}.wiz-editor-body ol.wiz-list-level2 > li {list-style-type:lower-lati ...

  7. 树莓派发射FM波——搭建私人小电台

    树莓派的应用十分广泛,有很多奇思妙想的应用非常有趣,在这里我们想实现一个小电台的功能,但是在这里需要说明,私人架设电台是违法行为,所以本案只作为自我娱乐所用,不能发射大功率的信号干扰正常的FM频段. ...

  8. maven 结合mybaits整合框架,打包时mapper.xml文件,mapper目录打不进war包去问题

    首先,来看下MAVENx项目标准的目录结构: 一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,ma ...

  9. LeetCode 题解之Plus One

    1.题目描述 2.题目分析 从后向前做加法,等于10则进位,否则直接加1 ,返回 digits; 3.代码 vector<int> plusOne(vector<int>&am ...

  10. PHP匹配当前传入是何种类型

    本文出至:新太潮流网络博客 /** * [is_string_regular_type 正则自动验证传入数据] * @E-mial wuliqiang_aa@163.com * @TIME 2017- ...