Skip to content

Commit 1955580

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents b758a51 + 067d976 commit 1955580

File tree

6 files changed

+309
-100
lines changed

6 files changed

+309
-100
lines changed

src/test/java/io/iconator/testonator/TestERC20.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void testEventMinting() throws NoSuchMethodException, InstantiationExcept
374374

375375
List<Event> events = blockchain.call(deployed,
376376
new FunctionBuilder("mint").addInput("address[]", addresses)
377-
.addInput("uint192[]", values));
377+
.addInput("uint256[]", values));
378378

379379
Assert.assertEquals(1, events.size());
380380
Assert.assertEquals("Transfer", events.get(0).name());
@@ -434,7 +434,7 @@ public void testEventMintAllFail() throws NoSuchMethodException, InstantiationEx
434434

435435
List<Event> events = blockchain.call(deployed,
436436
new FunctionBuilder("mint").addInput("address[]", addresses)
437-
.addInput("uint192[]", values));
437+
.addInput("uint256[]", values));
438438

439439
Assert.assertNull(events);
440440
}
@@ -452,7 +452,7 @@ public void testEventMintAll() throws NoSuchMethodException, InstantiationExcept
452452

453453
List<Event> events = blockchain.call(deployed,
454454
new FunctionBuilder("mint").addInput("address[]", addresses)
455-
.addInput("uint192[]", values));
455+
.addInput("uint256[]", values));
456456

457457
Assert.assertEquals(1, events.size());
458458
Assert.assertEquals("Transfer", events.get(0).name());
@@ -523,7 +523,7 @@ public void testLockup() throws NoSuchMethodException, InstantiationException, I
523523

524524
List<Event> events = blockchain.call(deployed,
525525
new FunctionBuilder("mint").addInput("address[]", addresses)
526-
.addInput("uint192[]", values));
526+
.addInput("uint256[]", values));
527527

528528
events = blockchain.call(deployed,
529529
new FunctionBuilder("lockTokens").addInput("address[]", addresses)
@@ -534,6 +534,9 @@ public void testLockup() throws NoSuchMethodException, InstantiationException, I
534534
Assert.assertEquals(CREDENTIAL_5.getAddress(), events.get(0).values().get(0).getValue().toString());
535535
Assert.assertEquals("2222", events.get(0).values().get(1).getValue().toString());
536536

537+
events = blockchain.call(deployed,
538+
new FunctionBuilder("setAdmin").addInput("address", TestBlockchain.CREDENTIAL_1.getAddress())
539+
.addInput("address", TestBlockchain.CREDENTIAL_2.getAddress()));
537540

538541
events = blockchain.call(deployed,
539542
new FunctionBuilder("finishMinting"));
@@ -563,12 +566,16 @@ public void testWithdrawTransferFrom() throws InterruptedException, ExecutionExc
563566

564567
List<Event> events = blockchain.call(deployed,
565568
new FunctionBuilder("mint").addInput("address[]", addresses)
566-
.addInput("uint192[]", values));
569+
.addInput("uint256[]", values));
567570

568571
events = blockchain.call(deployed,
569572
new FunctionBuilder("lockTokens").addInput("address[]", addresses)
570573
.addInput("uint256[]", values));
571574

575+
events = blockchain.call(deployed,
576+
new FunctionBuilder("setAdmin").addInput("address", TestBlockchain.CREDENTIAL_1.getAddress())
577+
.addInput("address", TestBlockchain.CREDENTIAL_2.getAddress()));
578+
572579
events = blockchain.call(deployed,
573580
new FunctionBuilder("finishMinting"));
574581
Assert.assertEquals(0, events.size());
@@ -603,12 +610,16 @@ public void testWithdraw() throws InterruptedException, ExecutionException, IOEx
603610

604611
List<Event> events = blockchain.call(deployed,
605612
new FunctionBuilder("mint").addInput("address[]", addresses)
606-
.addInput("uint192[]", values));
613+
.addInput("uint256[]", values));
607614

608615
events = blockchain.call(deployed,
609616
new FunctionBuilder("lockTokens").addInput("address[]", addresses)
610617
.addInput("uint256[]", values));
611618

619+
events = blockchain.call(deployed,
620+
new FunctionBuilder("setAdmin").addInput("address", TestBlockchain.CREDENTIAL_1.getAddress())
621+
.addInput("address", TestBlockchain.CREDENTIAL_2.getAddress()));
622+
612623
events = blockchain.call(deployed,
613624
new FunctionBuilder("finishMinting"));
614625
Assert.assertEquals(0, events.size());
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.iconator.testonator;
2+
3+
import org.junit.After;
4+
import org.junit.Assert;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
import org.web3j.abi.datatypes.Type;
8+
9+
import java.io.IOException;
10+
import java.lang.reflect.InvocationTargetException;
11+
import java.math.BigInteger;
12+
import java.util.List;
13+
import java.util.Map;
14+
import java.util.concurrent.ExecutionException;
15+
16+
import static io.iconator.testonator.TestBlockchain.CREDENTIAL_0;
17+
import static io.iconator.testonator.TestBlockchain.CREDENTIAL_1;
18+
19+
public class TestSnapshot {
20+
private static TestBlockchain blockchain;
21+
private static Map<String, Contract> contracts;
22+
23+
@BeforeClass
24+
public static void setup() throws Exception {
25+
blockchain = TestBlockchain.runLocal();
26+
contracts = TestUtils.setupSnapshot();
27+
}
28+
29+
@After
30+
public void afterTests() {
31+
blockchain.reset();
32+
}
33+
34+
@Test
35+
public void testTransfer() throws InterruptedException, ExecutionException, IOException, NoSuchMethodException, InstantiationException, IllegalAccessException, ConvertException, InvocationTargetException {
36+
//transfers: should transfer 10000 to accounts[1] with accounts[0] having 10000
37+
DeployedContract deployed = blockchain.deploy(CREDENTIAL_0, contracts.get("ERC20Snapshot"));
38+
DeployedContract deployedVoting = blockchain.deploy(CREDENTIAL_0, contracts.get("Voting"));
39+
mint(blockchain, deployed, deployedVoting, deployed.contractAddress());
40+
41+
blockchain.call(deployedVoting,
42+
new FunctionBuilder("vote").addInput("bool", true));
43+
44+
List<Type> ret = blockchain.callConstant(deployedVoting, new FunctionBuilder("yay").outputs("uint256"));
45+
46+
Assert.assertEquals("10000", ret.get(0).getValue().toString());
47+
48+
blockchain.call(deployed,
49+
new FunctionBuilder("transfer")
50+
.addInput("address", CREDENTIAL_1.getAddress())
51+
.addInput("uint256", new BigInteger("9999"))
52+
.outputs("bool"));
53+
54+
//credential 0 has voting power 1, as he transferred the rest to credential 1
55+
blockchain.call(deployedVoting,
56+
new FunctionBuilder("vote").addInput("bool", true));
57+
ret = blockchain.callConstant(deployedVoting, new FunctionBuilder("yay").outputs("uint256"));
58+
Assert.assertEquals("10001", ret.get(0).getValue().toString());
59+
60+
blockchain.call(deployed,
61+
new FunctionBuilder("transfer")
62+
.addInput("address", CREDENTIAL_1.getAddress())
63+
.addInput("uint256", new BigInteger("1"))
64+
.outputs("bool"));
65+
66+
//credential 0 has still voting power 1 even though he transferred 1 to credential 1, since its after block 8
67+
blockchain.call(deployedVoting,
68+
new FunctionBuilder("vote").addInput("bool", true));
69+
ret = blockchain.callConstant(deployedVoting, new FunctionBuilder("yay").outputs("uint256"));
70+
Assert.assertEquals("10002", ret.get(0).getValue().toString());
71+
72+
}
73+
74+
private static void mint(TestBlockchain blockchain, DeployedContract deployed, DeployedContract deployedVoting, String contractAddress) throws NoSuchMethodException, InstantiationException, IllegalAccessException, ConvertException, InvocationTargetException, InterruptedException, ExecutionException, IOException {
75+
blockchain.call(deployed,
76+
new FunctionBuilder("mint").addInput("address", TestBlockchain.CREDENTIAL_1.getAddress()));
77+
blockchain.call(deployedVoting,
78+
new FunctionBuilder("set").addInput("address", contractAddress));
79+
}
80+
}

src/test/java/io/iconator/testonator/TestUtils.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,24 @@ public static Map<String, Contract> setup() throws Exception {
2828
File contractFile1 = Paths.get(ClassLoader.getSystemResource("SafeMath.sol").toURI()).toFile();
2929
File contractFile2 = Paths.get(ClassLoader.getSystemResource("Utils.sol").toURI()).toFile();
3030
File contractFile3 = Paths.get(ClassLoader.getSystemResource("DOS.sol").toURI()).toFile();
31-
File contractFile4 = Paths.get(ClassLoader.getSystemResource("SafeMath192.sol").toURI()).toFile();
32-
Map<String, Contract> contracts = compile(contractFile3, contractFile1, contractFile2, contractFile4);
33-
Assert.assertEquals(6, contracts.size()); //DOS.sol has 3 (ERC20, DOS, ERC865Plus677ish), plus the other 3 are 6
31+
Map<String, Contract> contracts = compile(contractFile3, contractFile1, contractFile2);
32+
Assert.assertEquals(5, contracts.size()); //DOS.sol has 3 (ERC20, DOS, ERC865Plus677ish), plus the other 3 are 6
33+
for(String name:contracts.keySet()) {
34+
System.out.println("Available contract names: " + name);
35+
}
36+
TestUtils.contracts = contracts;
37+
return contracts;
38+
}
39+
40+
public static Map<String, Contract> setupSnapshot() throws Exception {
41+
if(contracts != null) {
42+
return contracts;
43+
}
44+
File contractFile1 = Paths.get(ClassLoader.getSystemResource("ERC20Snapshot.sol").toURI()).toFile();
45+
File contractFile2 = Paths.get(ClassLoader.getSystemResource("Voting.sol").toURI()).toFile();
46+
Map<String, Contract> contracts = compile(contractFile1);
47+
contracts.putAll(compile(contractFile2));
48+
Assert.assertEquals(3, contracts.size());
3449
for(String name:contracts.keySet()) {
3550
System.out.println("Available contract names: " + name);
3651
}
@@ -68,13 +83,17 @@ public static void mint(TestBlockchain blockchain, DeployedContract deployed, St
6883

6984
List<Event> events = blockchain.call(deployed,
7085
new FunctionBuilder("mint").addInput("address[]", addresses)
71-
.addInput("uint192[]", values));
86+
.addInput("uint256[]", values));
7287

7388
Assert.assertEquals(counter, events.size());
7489
if(value1 > 0) {
7590
Assert.assertEquals("" + value1, events.get(0).values().get(2).getValue().toString());
7691
}
7792

93+
events = blockchain.call(deployed,
94+
new FunctionBuilder("setAdmin").addInput("address", TestBlockchain.CREDENTIAL_1.getAddress())
95+
.addInput("address", TestBlockchain.CREDENTIAL_2.getAddress()));
96+
7897
if(setFlag) {
7998
events = blockchain.call(deployed,
8099
new FunctionBuilder("finishMinting"));

0 commit comments

Comments
 (0)