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. java设计模式-----15、适配器模式

    概念: Adapter模式也叫适配器模式,是构造型模式之一,通过Adapter模式可以改变已有类(或外部类)的接口形式. 举个例子:我们使用电脑,家里的电源是220V的,而我们的电脑是18V的,这时如 ...

  2. 适配器(GOF23)

    ---恢复内容开始--- 摘要:由于应用环境的变化,需要将现存的对象放到新的环境中去,但新环境的接口是现存对象不满足的. 意图:将原本接口不兼容的类通过转换,使得它们能够一起工作,复用现有的类 ada ...

  3. Python标准模块--concurrent.futures 进程池线程池终极用法

    concurrent.futures 这个模块是异步调用的机制concurrent.futures 提交任务都是用submitfor + submit 多个任务的提交shutdown 是等效于Pool ...

  4. 小tip: base64:URL背景图片与web页面性能优化——张鑫旭

    一.base64百科 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在HTTP环境下传递较长的标识信息. 某人: 唉,我彻底废柴了,为何上面明明是中文,洒家却看不懂嘞,为什 ...

  5. animation3 背景小动画笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 浏览器根对象document之方法概述

    1.1 节点 筛选 getRootNode返回上下文的根节点. querySelector返回文档中匹配指定 CSS 选择器的第一个元素. querySelectorAll返回文档中匹配指定 CSS ...

  7. MySQL的索引与优化

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  8. 润乾V4导出TXT时自定义分隔符

     ◆ 背景说明 报表中,导出text时,默认没有分隔符:应用中对导出Text,希望能自定义分隔符.在tag中定义了 textDataSeparator属性,让用户在导出Text时自定义分隔符,从而 ...

  9. 润乾配置连接kingbase(金仓)数据库

     问题背景 客户根据项目的不同,使用润乾连接的数据库类型各种各样,此文针对前几日使用润乾设计器连接kingbase金仓数据库做一个说明. kingbase金仓数据库是一款国产数据库,操作方式和配置 ...

  10. LeakCanary上传 leak trace 到服务器

    你可以改变处理完成的默认行为,将 leak trace 和 heap dump 上传到你的服务器以便统计分析. 创建一个 LeakUploadService, 最简单的就是继承 DisplayLeak ...