github.com/codingfuture/orig-energi3@v0.8.4/energi/consensus/migration_test.go (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of the Energi Core library. 3 // 4 // The Energi Core library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The Energi Core library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package consensus 18 19 import ( 20 "math/big" 21 "strings" 22 "testing" 23 24 "github.com/ethereum/go-ethereum/common" 25 26 "github.com/stretchr/testify/assert" 27 ) 28 29 const ( 30 testSnapshotData = ` 31 { 32 "snapshot_utxos": [ 33 { 34 "owner": "t6vtJKxdjaJdofaUrx7w4xUs5bMcjDq5R2", 35 "amount": 10228000000, 36 "type": "pubkeyhash" 37 }, 38 { 39 "owner": "tWFyUdwGxEkcam2aikVsDMPDpvMNKfP2XV", 40 "amount": 1000010, 41 "type": "pubkeyhash" 42 } 43 ], 44 "snapshot_blacklist": [ 45 "tWFyUdwGxEkcam2aikVsDMPDpvMNKfP2XV" 46 ], 47 "snapshot_hash": "778d7a438e3b86e0e754c4e46af802f852eb7c051d268c8599aa17c0cb9ce819" 48 } 49 ` 50 ) 51 52 func TestSnapshotParser(t *testing.T) { 53 t.Parallel() 54 55 ret, err := parseSnapshot(strings.NewReader(testSnapshotData)) 56 assert.Empty(t, err) 57 assert.Equal( 58 t, 59 ret.Hash, 60 "778d7a438e3b86e0e754c4e46af802f852eb7c051d268c8599aa17c0cb9ce819") 61 assert.Equal( 62 t, 63 len(ret.Txouts), 64 2) 65 assert.Equal( 66 t, 67 ret.Txouts[0].Owner, 68 "t6vtJKxdjaJdofaUrx7w4xUs5bMcjDq5R2") 69 assert.Equal( 70 t, 71 ret.Txouts[0].Atype, 72 "pubkeyhash") 73 assert.Equal( 74 t, 75 ret.Txouts[0].Amount.String(), 76 big.NewInt(10228000000).String()) 77 assert.Equal( 78 t, 79 ret.Txouts[1].Owner, 80 "tWFyUdwGxEkcam2aikVsDMPDpvMNKfP2XV") 81 assert.Equal( 82 t, 83 ret.Txouts[1].Atype, 84 "pubkeyhash") 85 assert.Equal( 86 t, 87 ret.Txouts[1].Amount.String(), 88 big.NewInt(1000010).String()) 89 assert.Equal( 90 t, 91 ret.Blacklist[0], 92 "tWFyUdwGxEkcam2aikVsDMPDpvMNKfP2XV") 93 } 94 95 func TestSnapshotParams(t *testing.T) { 96 t.Parallel() 97 98 snapshot, err := parseSnapshot(strings.NewReader(testSnapshotData)) 99 assert.Empty(t, err) 100 owners, amounts, blacklist := createSnapshotParams(snapshot) 101 assert.NotEmpty(t, owners) 102 assert.Equal( 103 t, 104 owners[0].String(), 105 common.HexToAddress("0x000D90BA0EFF81760202C28B40563B9636C1CCD4").String()) 106 assert.Equal( 107 t, 108 amounts[0].String(), 109 "102280000000000000000") 110 assert.Equal( 111 t, 112 owners[1].String(), 113 common.HexToAddress("0xFFF4AF0E7421838CDB2F14134F74AA4B5B0A816E").String()) 114 assert.Equal( 115 t, 116 amounts[1].String(), 117 "10000100000000000") 118 assert.Equal( 119 t, 120 blacklist[0].String(), 121 common.HexToAddress("0xFFF4AF0E7421838CDB2F14134F74AA4B5B0A816E").String()) 122 }