前言
结合项目的开发周期和测试需求,我们开发的合约在本地环境测试好后,同时需要在测试网络上进行测试,保证测试没有问题后切换到主网。接下来介绍如何将合约部署到测试网络上进行测试
操作流程
获取免费账户的地址:
http://faucet.cryptokylin.io/create_account?new_account_name
注意:new_account_name 为小写a-z,1-5,’.'组成,取名字的时候需要留意一下
- 创建部署合约账户,取名 myvoteradmin
http://faucet.cryptokylin.io/create_account?myvoteradmin
获得如下信息:其中公钥和私钥由测试平台创建
{"msg": "succeeded", "keys": {"active_key": {"public": "EOS6wDCweBb8gtHMzZSW2VYVYukXXYWHb9k46G9432eTzmcStXV16", "private": "5KA5vib9Nfi7kFmt8jTZiYGSWpcfthBQHhMB5b3s7SVLZ7jQb8b"}, "owner_key": {"public": "EOS7xcYiThknqxyYaa3b9Brw37rkdGtD1SM5L6RdNPG98Bj3wWyUj", "private": "5JkJcggdbeaj8sFUF6MAQj2yvpT3g5KChEJvMfUQ79UdPfSr4ne"}}, "account": "myvoteradmin"}
将相应active和ower的私钥导入到本地钱包。在操作之前记得解锁钱包
cleos wallet unlock
cleos wallet import --private-key 5KA5vib9Nfi7kFmt8jTZiYGSWpcfthBQHhMB5b3s7SVLZ7jQb8b
imported private key for: EOS6wDCweBb8gtHMzZSW2VYVYukXXYWHb9k46G9432eTzmcStXV16
- 创建测试用户 myvotertest1、myvotertest2
http://faucet.cryptokylin.io/create_account?myvotertest1
{"msg": "succeeded", "keys": {"active_key": {"public": "EOS8QZQDun9dEXjogEBwUyRHvBFU6WfBUMjXD7PUEpQt2pxNbZsfo", "private": "5JAaVWD6JhC1AX635Vn4MN4ZVpw4Bv4YGQ9NxBvLnPT53KEW3Mi"}, "owner_key": {"public": "EOS5XzvENwSPSZDRqcDjmu6PVH6fyuvUPcMWWNU2SWxuFYSf8a6WN", "private": "5K2ASBTJGGNGitrQwoeHr4KwgumpFXYohx31Duyajan2k2aYgUg"}}, "account": "myvotertest1"}
http://faucet.cryptokylin.io/create_account?myvotertest2
{"msg": "succeeded", "keys": {"active_key": {"public": "EOS7PuKshtysiKXaYNkJLNoNkoHjX4r4RYPbb6aQJ4mzVTUN3dF62", "private": "5JrxTXSBT4Yjo2Qd1WuegkrSqPZh98kgfcbhuFQMw6wfN5qS3fh"}, "owner_key": {"public": "EOS6PLZNv4SeKbi5kYy5BahzVQJHDs1gqBxCC5B2Yj5YGuWuJN5St", "private": "5KTpGz6w29aSAq2RNWc8ciXyDVVJKdFWHzenP5VbAMBgFF7icaE"}}, "account": "myvotertest2"}
将相应的active的私钥导入到本地钱包。
cleos wallet import --private-key 5JAaVWD6JhC1AX635Vn4MN4ZVpw4Bv4YGQ9NxBvLnPT53KEW3Mi
imported private key for: EOS6wDCweBb8gtHMzZSW2VYVYukXXYWHb9k46G9432eTzmcStXV16
cleos wallet import --private-key 5JrxTXSBT4Yjo2Qd1WuegkrSqPZh98kgfcbhuFQMw6wfN5qS3fh
imported private key for: EOS6wDCweBb8gtHMzZSW2VYVYukXXYWHb9k46G9432eTzmcStXV16
- 获取免费的EOS token
每次可以获取100个,每天最多1000个
http://faucet.cryptokylin.io/get_token?myvoteradmin
http://faucet.cryptokylin.io/get_token?myvotertest1
http://faucet.cryptokylin.io/get_token?myvotertest2
- 查看网络信息
cleos -u http://kylin.fn.eosbixin.com get info
{
"server_version": "f9a3d023",
"chain_id": "5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191",
"head_block_num": 17227997,
"last_irreversible_block_num": 17227669,
"last_irreversible_block_id": "0106df95091ec435024957f8a89d27045a1d20f2f3ff78611e59782a92367d3f",
"head_block_id": "0106e0dd4ce76fd773462a2107fdc2a3c9018bb0cdfeae17edd3461c71cf63e6",
"head_block_time": "2018-10-25T08:14:50.000",
"head_block_producer": "eosasia11111",
"virtual_block_cpu_limit": 250000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 246080,
"block_net_limit": 1047688,
"server_version_string": "v1.4.1"
}
5.购买CPU、NET、RAM
我们知道在EOS上执行action的时候免费,但是运行的过程过程中需要消耗CPU、NET、RAM,这些资源则需要我们购买或者抵押,其中RAM为购买,CPU和NET按照抵押EOS的多少,计算分配你多少资源使用。所以说我们看到在主网上创建EOS账户实际上是需要付费的,如果是合约账户,为了保证我们合约的稳定运行,就需要购买更多的资源。
购买RAM
cleos -u http://kylin.fn.eosbixin.com system buyram myvoteradmin myvoteradmin "10 EOS"
executed transaction: 920e34b62a90c101cdc734fb99eb06dde198b2f4dbb6ed803b49cfb9b786c375 128 bytes 971 us
# eosio <= eosio::buyram {"payer":"myvoteradmin","receiver":"myvoteradmin","quant":"10.0000 EOS"}
# eosio.token <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# myvoteradmin <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# eosio.ram <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# eosio.token <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
# myvoteradmin <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
# eosio.ramfee <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
CPU、NET分别抵押1EOS
cleos -u http://kylin.fn.eosbixin.com system delegatebw myvoteradmin myvoteradmin "1 EOS" "1 EOS"
executed transaction: 8339b9c8223696df57d190b4b8642f5ced2e59122375962ff339b3c1f6b301e1 144 bytes 1162 us
# eosio <= eosio::delegatebw {"from":"myvoteradmin","receiver":"myvoteradmin","stake_net_quantity":"1.0000 EOS","stake_cpu_quanti...
# eosio.token <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.stake","quantity":"2.0000 EOS","memo":"stake bandwidth"}
# myvoteradmin <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.stake","quantity":"2.0000 EOS","memo":"stake bandwidth"}
# eosio.stake <= eosio.token::transfer {"from":"myvoteradmin","to":"eosio.stake","quantity":"2.0000 EOS","memo":"stake bandwidth"}
- 资源准备好后,我们将合约部署到测试网络上
cleos -u http://kylin.fn.eosbixin.com set contract myvoteradmin vote
Reading WASM from vote/vote.wasm...
Publishing contract...
executed transaction: 3caf68d169da369e172a4e1c1ad3e70f664284af110244e8655541d18ea51f9f 8008 bytes 1633 us
# eosio <= eosio::setcode {"account":"myvoteradmin","vmtype":0,"vmversion":0,"code":"0061736d0100000001b9011d60017f0060037f7e7...
# eosio <= eosio::setabi {"account":"myvoteradmin","abi":"0e656f73696f3a3a6162692f312e3000070c61646463616e6469646174650003076...
- 测试合约action
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin version '[]' -p myvoteradmin@active
executed transaction: 8c2acb486904f7731bae715e65230c70422dc9f21e20d98ec06caccc022d94ea 96 bytes 338 us
# myvoteradmin <= myvoteradmin::version ""
>> vote system version 1.0.0
- 添加投票主题
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin addtheme '["myvoteradmin","2018最美乡村选举"]' -p myvoteradmin@active
executed transaction: be810b213bd06095042be18df8a4356c067e3960a19447ae05f79e03e966a65e 128 bytes 458 us
# myvoteradmin <= myvoteradmin::addtheme {"account":"myvoteradmin","theme":"2018最美乡村选举"}
>> Add new poll theme: 2018最美乡村选举
- 添加候选人
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin addcandidate '["myvoteradmin","2018最美乡村选举","雪乡"]' -p myvoteradmin@active
executed transaction: 9decfb1596417bf5e13bff01cacaf8ece058bcd39ef3ec23e3e7822570a0382a 136 bytes 710 us
# myvoteradmin <= myvoteradmin::addcandidate {"account":"myvoteradmin","theme":"2018最美乡村选举","name":"雪乡"}
>> Add new candidate : 雪乡
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin addcandidate '["myvoteradmin","2018最美乡村选举","图瓦村"]' -p myvoteradmin@active
executed transaction: ea27d763e717b4ef430141292ff0fdf5b80e211fe351599c0b671af6678b1281 136 bytes 607 us
# myvoteradmin <= myvoteradmin::addcandidate {"account":"myvoteradmin","theme":"2018最美乡村选举","name":"图瓦村"}
>> Add new candidate : 图瓦村
- 投票
myvotertest1用户对图瓦村投票
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin poll '["myvotertest1","2018最美乡村选举","图瓦村"]' -p myvotertest1@active
executed transaction: 4a55e49e4f7e590a11841ddda0ed2f5f5e2840ef96d82f22d30561e1c2bcd8b1 136 bytes 659 us
# myvoteradmin <= myvoteradmin::poll {"account":"myvotertest1","theme":"2018最美乡村选举","name":"图瓦村"}
>> vote success
myvotertest2用户对图雪乡投票
cleos -u http://kylin.fn.eosbixin.com push action myvoteradmin poll '["myvotertest2","2018最美乡村选举","雪乡"]' -p myvotertest2@active
executed transaction: 06b8ed6fa3b883da1105ce531bd04446070dea4b360175a56ba38f42638a0330 136 bytes 782 us
# myvoteradmin <= myvoteradmin::poll {"account":"myvotertest2","theme":"2018最美乡村选举","name":"雪乡"}
>> vote success
- 查看数据库中的投票数据
cleos -u http://kylin.fn.eosbixin.com get table myvoteradmin myvoteradmin pollrecord
{
"rows": [{
"id": 0,
"pollthemeId": 0,
"candidateId": 1,
"user": "myvotertest1"
},{
"id": 1,
"pollthemeId": 0,
"candidateId": 0,
"user": "myvotertest2"
}
],
"more": false
}
cleos -u http://kylin.fn.eosbixin.com get table myvoteradmin myvoteradmin candidate
{
"rows": [{
"id": 0,
"pollthemeId": 0,
"candidateName": "雪乡",
"count": 1
},{
"id": 1,
"pollthemeId": 0,
"candidateName": "图瓦村",
"count": 1
}
],
"more": false
}
cleos -u http://kylin.fn.eosbixin.com get table myvoteradmin myvoteradmin polltheme
{
"rows": [{
"id": 0,
"themeName": "2018最美乡村选举",
"status": 0,
"count": 2
}
],
"more": false
}