5858 timeThreshold = 30
5959)
6060
61- func setUpVoteJournal (t * testing.T ) * VoteJournal {
62- // Create a temporary file for the votes journal
63- file , err := ioutil .TempFile ("" , "" )
64- if err != nil {
65- t .Fatalf ("failed to create temporary file path: %v" , err )
66- }
67- journal := file .Name ()
68- defer os .Remove (journal )
69-
70- // Clean up the temporary file, we only need the path for now
71- file .Close ()
72- os .Remove (journal )
73-
74- voteJournal , err := NewVoteJournal (journal )
75- if err != nil {
76- t .Fatalf ("failed to create temporary votes journal: %v" , err )
77- }
78-
79- return voteJournal
80- }
81-
8261func (pool * VotePool ) verifyStructureSizeOfVotePool (receivedVotes , curVotes , futureVotes , curVotesPq , futureVotesPq int ) bool {
8362 for i := 0 ; i < timeThreshold ; i ++ {
8463 time .Sleep (1 * time .Second )
@@ -104,10 +83,7 @@ func (journal *VoteJournal) verifyJournal(size, lastLatestVoteNumber int) bool {
10483}
10584
10685func TestVotePool (t * testing.T ) {
107- km := setUpKeyManager (t )
108-
109- // Create vote Signer
110- voteSigner , _ := NewVoteSigner (km )
86+ walletPasswordDir , walletDir := setUpKeyManager (t )
11187
11288 // Create a database pre-initialize with a genesis block
11389 db := rawdb .NewMemoryDatabase ()
@@ -119,18 +95,29 @@ func TestVotePool(t *testing.T) {
11995
12096 mux := new (event.TypeMux )
12197
122- // Create vote journal
123- voteJournal := setUpVoteJournal (t )
124-
12598 // Create vote pool
12699 votePool := NewVotePool (params .TestChainConfig , chain , ethash .NewFaker ())
127100
128101 // Create vote manager
129- voteManager , err := NewVoteManager (mux , params .TestChainConfig , chain , voteJournal , voteSigner , votePool )
102+ // Create a temporary file for the votes journal
103+ file , err := ioutil .TempFile ("" , "" )
104+ if err != nil {
105+ t .Fatalf ("failed to create temporary file path: %v" , err )
106+ }
107+ journal := file .Name ()
108+ defer os .Remove (journal )
109+
110+ // Clean up the temporary file, we only need the path for now
111+ file .Close ()
112+ os .Remove (journal )
113+
114+ voteManager , err := NewVoteManager (mux , params .TestChainConfig , chain , votePool , journal , walletPasswordDir , walletDir )
130115 if err != nil {
131116 t .Fatalf ("failed to create vote managers" )
132117 }
133118
119+ voteJournal := voteManager .journal
120+
134121 // Send the done event of downloader
135122 time .Sleep (10 * time .Millisecond )
136123 mux .Post (downloader.DoneEvent {})
@@ -267,15 +254,24 @@ func TestVotePool(t *testing.T) {
267254 }
268255}
269256
270- func setUpKeyManager (t * testing.T ) * keymanager.IKeymanager {
257+ func setUpKeyManager (t * testing.T ) (string , string ) {
258+ walletDir := filepath .Join (t .TempDir (), "wallet" )
271259 walletConfig := & accounts.CreateWalletConfig {
272260 WalletCfg : & wallet.Config {
273- WalletDir : filepath . Join ( t . TempDir (), "wallet" ) ,
261+ WalletDir : walletDir ,
274262 KeymanagerKind : keymanager .Imported ,
275263 WalletPassword : password ,
276264 },
277265 SkipMnemonicConfirm : true ,
278266 }
267+ walletPasswordDir := filepath .Join (t .TempDir (), "password" )
268+ if err := os .MkdirAll (filepath .Dir (walletPasswordDir ), 0700 ); err != nil {
269+ t .Fatalf ("failed to create walletPassword dir: %v" , err )
270+ }
271+ if err := ioutil .WriteFile (walletPasswordDir , []byte (password ), 0600 ); err != nil {
272+ t .Fatalf ("failed to write wallet password dir: %v" , err )
273+ }
274+
279275 w , err := accounts .CreateWalletWithKeymanager (context .Background (), walletConfig )
280276 if err != nil {
281277 t .Fatalf ("failed to create wallet: %v" , err )
@@ -308,5 +304,5 @@ func setUpKeyManager(t *testing.T) *keymanager.IKeymanager {
308304 Keystores : []* keymanager.Keystore {keystore },
309305 AccountPassword : password ,
310306 })
311- return & km
307+ return walletPasswordDir , walletDir
312308}
0 commit comments