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. manven springmvc 项目中 slf4j 的配置使用(结合log4j 或者 logback)

    前言:每个maven springmvc 都应该有日志功能,SLF4J(Simple logging facade for Java)就是一种日志规范,它提供了一个共通接口,可以适配多种不同的LOG实 ...

  2. java设计模式-----13、组合模式

    Composite模式也叫组合模式,是构造型的设计模式之一.通过递归手段来构造树形的对象结构,并可以通过一个对象来访问整个对象树. 组合(Composite)模式的其它翻译名称也很多,比如合成模式.树 ...

  3. bzoj3167 [Heoi2013]Sao

    传送门 这题神坑啊……明明是你菜 首先大家都知道原题等价于给每个点分配一个$1$~$n$且两两不同的权值,同时还需要满足一些大于/小于关系的方案数. 先看一眼数据范围,既然写明了$n\le 1000$ ...

  4. WDCP上传SSL证书

    1.在线申请SSL证书 2.网站管理>SSL证书上传 3.将key文件直接上传,cert文件内容复制到crt文件中,再上传 4.开启https 注意:同一个域名下解析的若干域名,只能走主域名的证 ...

  5. opencv图像处理时使用文件输入流ifstream批量读取图片

    简介: 在利用opencv进行图像处理时,通常需要批量读取图片,然后做相应的处理,我们可以用C++文件的输入流来进行图片的读取,这要求我们应该事先,将图片图片名生成txt文件,具体请参见之前的博文[u ...

  6. Spring Boot—20Zookeeper

    https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/ pom.xml <dependency&g ...

  7. 安卓脱壳&&协议分析&&burp辅助分析插件编写

    前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 前言 本文以一个 app 为例,演示对 app脱壳,然后分析其 协 ...

  8. Pig模式

    Pig中的模式可以是用户显示声明的,也可以是Pig通过用户的使用方式猜测的. Pig对模式的认知在Pig Latin脚本执行的不同阶段可能是不同的.     下面的语句,用户显示声明了模式:3个字段, ...

  9. Oracle EBS 取总账期间

    --取期间 select GPS.EFFECTIVE_PERIOD_NUM, GPS.PERIOD_NAME from GL_PERIOD_STATUSES GPS AND (GPS.SET_OF_B ...

  10. Oracle使用order by排序关于null值处理

    select * from dual order by age desc nulls last select * from test order by age asc nulls first sqls ...