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. 插入sql返回主键id

    <insert id="insertSelective" parameterType="com.xxx.model.XDetail" useGenerat ...

  2. 简单创建json格式文件

    简单创建json格式文件 核心就两点: addProperty 添加属性(也就是加键值对) add是添加 另外的object对象 然后直接toString()输出 核心代码如下; public cla ...

  3. EF 多种查询方式

    比较常用的查询方式linq to entity,这里先看一种写法: var query = (from d in testContext.Set<DepartPerson>() //查询和 ...

  4. 后台管理UI+功能

    kingRoad功能强大,丰富各种功能和插件,自定义开发功能组件及样式,使用webpack方式集成和纯html两种,UI(自定义开发和AdminLTE的集成优化),弹窗功能使用(Layer弹窗,并与框 ...

  5. Linux 文件缓存 (二)

    close系统调用入口1. 首先来到系统调用入口,主要使用__close_fd进行了具体的处理过程,并没有耗时操作.(current->files表示进程当前打开文件表信息,fd为需要关闭的文件 ...

  6. 【PyQt5 学习记录】005:QMainWindow 及状态栏、菜单栏和工具栏

    #!/usr/bin/env python import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QA ...

  7. c# 后台异步请求接口

    第一步:引用程序集:Systen.Net.Http 第一种方式: 异步 Get请求 HttpClient client = new HttpClient();            //client. ...

  8. top,job,user,file,alias

    1.系统进程 2.系统资源管理 3.作业管理 4.用户管理 5.文件权限 6.别名定义       一.系统进程 1.进程的定义 进程是操作系统的概念,每当我们执行一个程序时,对于操作系统来讲就创建了 ...

  9. 关于Oracle中sys、system和Scott用户下的数据库连接问题

    system默认:manager sys默认:change_on_install 使用SQL Plus登录数据库时,system使用密码manager可直接登录. 由于为自己的密码时更改过的,所以我的 ...

  10. Visual Studio 下nuget命令的使用

    从Visual Studio 2012版本开始默认集成了Nuget扩展,在Visual Studio 2010或以下的版本需要单独安装,安装方法如下: 1. “工具”→“扩展和更新...”,弹出扩展管 ...