Repository navigation
Expand file tree
/
Copy pathVotesStoreTest.java
More file actions
executable file
·65 lines (55 loc) · 2.2 KB
/
Copy pathVotesStoreTest.java
File metadata and controls
executable file
·65 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.tron.core.db;
import com.google.protobuf.ByteString;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.utils.FileUtil;
import org.tron.core.Constant;
import org.tron.core.capsule.VotesCapsule;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;
import org.tron.protos.Protocol.Vote;
@Slf4j
public class VotesStoreTest {
private static final String dbPath = "output-votesStore-test";
private static TronApplicationContext context;
VotesStore votesStore;
static {
Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF);
context = new TronApplicationContext(DefaultConfig.class);
}
@Before
public void initDb() {
this.votesStore = context.getBean(VotesStore.class);
}
@AfterClass
public static void destroy() {
Args.clearParam();
context.destroy();
FileUtil.deleteDir(new File(dbPath));
}
@Test
public void putAndGetVotes() {
List<Vote> oldVotes = new ArrayList<Vote>();
VotesCapsule votesCapsule = new VotesCapsule(ByteString.copyFromUtf8("100000000x"), oldVotes);
this.votesStore.put(votesCapsule.createDbKey(), votesCapsule);
Assert.assertTrue("votesStore is empyt", votesStore.iterator().hasNext());
Assert.assertTrue(votesStore.has(votesCapsule.createDbKey()));
VotesCapsule votesSource = this.votesStore
.get(ByteString.copyFromUtf8("100000000x").toByteArray());
Assert.assertEquals(votesCapsule.getAddress(), votesSource.getAddress());
Assert.assertEquals(ByteString.copyFromUtf8("100000000x"), votesSource.getAddress());
// votesCapsule = new VotesCapsule(ByteString.copyFromUtf8(""), oldVotes);
// this.votesStore.put(votesCapsule.createDbKey(), votesCapsule);
// votesSource = this.votesStore.get(ByteString.copyFromUtf8("").toByteArray());
// Assert.assertEquals(votesStore.getAllVotes().size(), 2);
// Assert.assertEquals(votesCapsule.getAddress(), votesSource.getAddress());
// Assert.assertEquals(null, votesSource.getAddress());
}
}