From 35e16e9bdb475ff0fb9b7793aaff89bae18516a8 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Thu, 14 Mar 2019 14:47:51 -0700 Subject: [PATCH] add test --- node/contract.go | 2 ++ node/contract_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 node/contract_test.go diff --git a/node/contract.go b/node/contract.go index 9583235eb..c7b463e3a 100644 --- a/node/contract.go +++ b/node/contract.go @@ -116,6 +116,8 @@ func (node *Node) AddLotteryContract() { priKey, err := crypto.HexToECDSA(contract_constants.DemoAccounts[0].Private) if err != nil { utils.GetLogInstance().Error("Error when creating private key for demo contract") + // Exit here to recognize the coding working. + // Basically we will remove this logic when launching so it's fine for now. os.Exit(1) } diff --git a/node/contract_test.go b/node/contract_test.go new file mode 100644 index 000000000..70c0b637d --- /dev/null +++ b/node/contract_test.go @@ -0,0 +1,32 @@ +package node + +import ( + "testing" + + "github.com/harmony-one/harmony/consensus" + "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/p2p" + "github.com/harmony-one/harmony/p2p/p2pimpl" +) + +func prepareNode(t *testing.T) *Node { + _, pubKey := utils.GenKey("1", "2") + leader := p2p.Peer{IP: "127.0.0.1", Port: "8882", ConsensusPubKey: pubKey} + validator := p2p.Peer{IP: "127.0.0.1", Port: "8885"} + priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902") + host, err := p2pimpl.NewHost(&leader, priKey) + if err != nil { + t.Fatalf("newhost failure: %v", err) + } + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + return New(host, consensus, nil) + +} + +func TestAddLotteryContract(t *testing.T) { + node := prepareNode(t) + node.AddLotteryContract() + if len(node.DemoContractAddress) == 0 { + t.Error("Can not create demo contract") + } +}