Skip to content

Commit

Permalink
Constrained the minimum unity fork number to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Oct 21, 2019
1 parent 3b5bf3e commit 57c09ea
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ protected AionBlockchainImpl(
this.forkUtility = new ForkUtility(); // forks are disabled by default
Optional<Long> maybeFork050 = load050ForkNumberFromConfig(CfgAion.inst());
if (maybeFork050.isPresent()) {
if (maybeFork050.get() < 2) { // AKI-419, Constrain the minimum unity fork number
LOG.warn("The unity fork number cannot be less than 2, set the fork number to 2");
maybeFork050 = Optional.of(2L);
}

this.forkUtility.enableUnityFork(maybeFork050.get());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.aion.zero.impl.blockchain;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Properties;
import org.aion.zero.impl.config.CfgAion;
import org.junit.After;
import org.junit.Test;

public class AionBlockchainImplTest {

private StandaloneBlockchain blockchain;

@After
public void tearDown() {

CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", String.valueOf(Long.MAX_VALUE));
cfg.getFork().setProperties(p);
this.blockchain = null;
}

@Test
public void testUnityMininmumNumber() {
CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", "1");
cfg.getFork().setProperties(p);

StandaloneBlockchain.Bundle bundle =
new StandaloneBlockchain.Builder()
.withDefaultAccounts()
.withValidatorConfiguration("simple")
.build();
this.blockchain = bundle.bc;

assertNotNull(blockchain);
//AKI-419 the minimum fork point is 2, therefore, the unity protocol will start from 3
assertFalse(blockchain.forkUtility.isUnityForkActive(2));
assertTrue(blockchain.forkUtility.isUnityForkActive(3));
}

@Test
public void testUnityMininmumNumber2() {
CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", "2");
cfg.getFork().setProperties(p);

StandaloneBlockchain.Bundle bundle =
new StandaloneBlockchain.Builder()
.withDefaultAccounts()
.withValidatorConfiguration("simple")
.build();
this.blockchain = bundle.bc;

assertNotNull(blockchain);
assertFalse(blockchain.forkUtility.isUnityForkActive(2));
assertTrue(blockchain.forkUtility.isUnityForkActive(3));
}
}

0 comments on commit 57c09ea

Please sign in to comment.