github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/accounts/abi/bind/util_test.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package bind_test 18 19 import ( 20 "github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind" 21 "github.com/PlatONnetwork/PlatON-Go/common" 22 "github.com/PlatONnetwork/PlatON-Go/crypto" 23 "testing" 24 ) 25 26 var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 27 28 var waitDeployedTests = map[string]struct { 29 code string 30 gas uint64 31 wantAddress common.Address 32 wantErr error 33 }{ 34 "successful deploy": { 35 code: `6060604052600a8060106000396000f360606040526008565b00`, 36 gas: 3000000, 37 wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"), 38 }, 39 "empty code": { 40 code: ``, 41 gas: 300000, 42 wantErr: bind.ErrNoCodeAfterDeploy, 43 wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"), 44 }, 45 } 46 47 func TestWaitDeployed(t *testing.T) { 48 /*db := ethdb.NewMemDatabase() 49 ppos_storage.NewPPosTemp(db) 50 for name, test := range waitDeployedTests { 51 backend := backends.NewSimulatedBackend( 52 core.GenesisAlloc{ 53 crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000)}, 54 }, 10000000, 55 ) 56 57 // Create the transaction. 58 tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code)) 59 tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey) 60 61 // Wait for it to get mined in the background. 62 var ( 63 err error 64 address common.Address 65 mined = make(chan struct{}) 66 ctx = context.Background() 67 ) 68 go func() { 69 address, err = bind.WaitDeployed(ctx, backend, tx) 70 close(mined) 71 }() 72 73 // Send and mine the transaction. 74 backend.SendTransaction(ctx, tx) 75 backend.Commit() 76 77 select { 78 case <-mined: 79 if err != test.wantErr { 80 t.Errorf("test %q: error mismatch: got %q, want %q", name, err, test.wantErr) 81 } 82 if address != test.wantAddress { 83 t.Errorf("test %q: unexpected contract address %s", name, address.Hex()) 84 } 85 case <-time.After(2 * time.Second): 86 t.Errorf("test %q: timeout", name) 87 } 88 }*/ 89 }