Skip to content

Commit

Permalink
More State tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 3, 2024
1 parent d00a2e8 commit ec3a85a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
16 changes: 11 additions & 5 deletions convex-core/src/main/java/convex/core/cvm/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ public State putAccount(Address address, AccountStatus accountStatus) {
*/
public AccountStatus getAccount(Address target) {
long ix=target.longValue();
return getAccount(ix);
}

public AccountStatus getAccount(long ix) {
AVector<AccountStatus> accts=getAccounts();
if ((ix<0)||(ix>=accts.count())) return null;
return accts.get(ix);
Expand Down Expand Up @@ -725,11 +729,6 @@ public void validate() throws InvalidDataException {
super.validate();
}

@Override
public void validateCell() throws InvalidDataException {
// nothing to do?
}

/**
* Gets the current global timestamp from this state.
*
Expand All @@ -739,6 +738,11 @@ public CVMLong getTimestamp() {
return (CVMLong) getGlobals().get(GLOBAL_TIMESTAMP);
}

@Override
public void validateCell() throws InvalidDataException {
// nothing to do?
}

/**
* Gets the current Juice price
*
Expand Down Expand Up @@ -960,4 +964,6 @@ protected State withValues(AVector<ACell> newValues) {





}
14 changes: 14 additions & 0 deletions convex-core/src/test/java/convex/core/init/InitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
import convex.core.cvm.PeerStatus;
import convex.core.cvm.State;
import convex.core.data.AccountKey;
import convex.core.data.Blob;
import convex.core.data.Format;
import convex.core.data.Hash;
import convex.core.data.MapEntry;
import convex.core.data.Ref;
import convex.core.data.Refs;
import convex.core.data.prim.CVMLong;
import convex.core.exceptions.BadFormatException;
import convex.core.exceptions.InvalidDataException;
import convex.core.lang.ACVMTest;
import convex.core.lang.Core;

/**
* Tests for Init functionality
Expand Down Expand Up @@ -115,6 +119,16 @@ public void testMemoryExchange() {
assertEquals(Constants.INITIAL_MEMORY_POOL*Constants.INITIAL_MEMORY_PRICE,cvx.longValue());
}

@Test
public void testInitEncoding() throws BadFormatException {
Blob b=Format.encodeMultiCell(STATE, true);

State s=Format.decodeMultiCell(b);
assertEquals(STATE,s);
assertEquals(STATE.getAccount(Core.CORE_ADDRESS),s.getAccount(Core.CORE_ADDRESS));
assertEquals(STATE.getAccount(29),s.getAccount(29));
}

@Test
public void testInitRef() {
State s=STATE;
Expand Down

0 comments on commit ec3a85a

Please sign in to comment.