Skip to content

Commit

Permalink
eliminada addEZI(), refactorizado payable con Math.floor(), refactori…
Browse files Browse the repository at this point in the history
…zados casos test
  • Loading branch information
dfleta committed Feb 27, 2019
1 parent 25df029 commit f5e3fff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/java/enzinium/TokenContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public int totalTokensSold() {
public void payable(PublicKey recipient, Double enziniums) {
try {
require(enziniums >= this.getTokenPrice());
Double units = Math.ceil(enziniums / tokenPrice);
Double units = Math.floor(enziniums / tokenPrice);
transfer(recipient, units);
this.owner.transferEZI(enziniums);
} catch (Exception e) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/enzinium/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public void transferEZI_test() {
rick.generateKeyPair();

rick.transferEZI(20d);

rick.transferEZI(20d);

assertEquals(40d, rick.getBalance(), 0d);
}

}
48 changes: 17 additions & 31 deletions src/test/java/enzinium/TokenContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

public class TokenContractTest {

@Test
public void addOwner_test() {
private Address rick = null;
private Address morty = null;
TokenContract ricknillos = null;

@Before
public void setup_contract() {

Address rick = new Address();
rick = new Address();
rick.generateKeyPair();
TokenContract ricknillos = new TokenContract(rick);
ricknillos = new TokenContract(rick);
ricknillos.addOwner(rick.getPK(), 100d);
assertEquals(1, ricknillos.getBalances().size());

Address morty = new Address();
morty = new Address();
morty.generateKeyPair();
}

@Test
public void addOwner_test() {

ricknillos.addOwner(morty.getPK(), 0d);
assertEquals(2, ricknillos.getBalances().size());

Expand All @@ -27,15 +37,6 @@ public void addOwner_test() {

@Test
public void balanceOf_test() {

Address rick = new Address();
rick.generateKeyPair();
TokenContract ricknillos = new TokenContract(rick);
ricknillos.addOwner(rick.getPK(), 100d);
assertEquals(1, ricknillos.getBalances().size());

Address morty = new Address();
morty.generateKeyPair();

assertEquals(100d, ricknillos.balanceOf(rick.getPK()), 0d);
// chequeo getOrDefault(PK, 0d) para direcciones que no existen
Expand All @@ -45,15 +46,6 @@ public void balanceOf_test() {
@Test
public void transfer_test() {

Address rick = new Address();
rick.generateKeyPair();
TokenContract ricknillos = new TokenContract(rick);
ricknillos.addOwner(rick.getPK(), 100d);
assertEquals(1, ricknillos.getBalances().size());

Address morty = new Address();
morty.generateKeyPair();

ricknillos.transfer(morty.getPK(), 2d);
assertEquals(2d, ricknillos.balanceOf(morty.getPK()), 0d);
assertEquals(98d, ricknillos.balanceOf(rick.getPK()), 0d);
Expand All @@ -66,13 +58,6 @@ public void transfer_test() {
@Test
public void payable_test() {

Address rick = new Address();
rick.generateKeyPair();
TokenContract ricknillos = new TokenContract(rick);
ricknillos.addOwner(rick.getPK(), 100d);
Address morty = new Address();
morty.generateKeyPair();

morty.transferEZI(20d);

// verifico la transferencia de entradas
Expand All @@ -86,8 +71,9 @@ public void payable_test() {
assertEquals(4d, ricknillos.balanceOf(morty.getPK()), 0d);
assertEquals(20d, ricknillos.owner().getBalance(), 0d);

// intento de compra de media entrada
ricknillos.payable(morty.getPK(), 8d);
assertEquals(5d, ricknillos.balanceOf(morty.getPK()), 0d);
assertEquals(20d, ricknillos.owner().getBalance(), 0d);
assertEquals(28d, ricknillos.owner().getBalance(), 0d);
}
}

0 comments on commit f5e3fff

Please sign in to comment.