Skip to content

Commit ec3a85a

Browse files
committed
More State tests
1 parent d00a2e8 commit ec3a85a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

convex-core/src/main/java/convex/core/cvm/State.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ public State putAccount(Address address, AccountStatus accountStatus) {
642642
*/
643643
public AccountStatus getAccount(Address target) {
644644
long ix=target.longValue();
645+
return getAccount(ix);
646+
}
647+
648+
public AccountStatus getAccount(long ix) {
645649
AVector<AccountStatus> accts=getAccounts();
646650
if ((ix<0)||(ix>=accts.count())) return null;
647651
return accts.get(ix);
@@ -725,11 +729,6 @@ public void validate() throws InvalidDataException {
725729
super.validate();
726730
}
727731

728-
@Override
729-
public void validateCell() throws InvalidDataException {
730-
// nothing to do?
731-
}
732-
733732
/**
734733
* Gets the current global timestamp from this state.
735734
*
@@ -739,6 +738,11 @@ public CVMLong getTimestamp() {
739738
return (CVMLong) getGlobals().get(GLOBAL_TIMESTAMP);
740739
}
741740

741+
@Override
742+
public void validateCell() throws InvalidDataException {
743+
// nothing to do?
744+
}
745+
742746
/**
743747
* Gets the current Juice price
744748
*
@@ -960,4 +964,6 @@ protected State withValues(AVector<ACell> newValues) {
960964

961965

962966

967+
968+
963969
}

convex-core/src/test/java/convex/core/init/InitTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
import convex.core.cvm.PeerStatus;
1919
import convex.core.cvm.State;
2020
import convex.core.data.AccountKey;
21+
import convex.core.data.Blob;
22+
import convex.core.data.Format;
2123
import convex.core.data.Hash;
2224
import convex.core.data.MapEntry;
2325
import convex.core.data.Ref;
2426
import convex.core.data.Refs;
2527
import convex.core.data.prim.CVMLong;
28+
import convex.core.exceptions.BadFormatException;
2629
import convex.core.exceptions.InvalidDataException;
2730
import convex.core.lang.ACVMTest;
31+
import convex.core.lang.Core;
2832

2933
/**
3034
* Tests for Init functionality
@@ -115,6 +119,16 @@ public void testMemoryExchange() {
115119
assertEquals(Constants.INITIAL_MEMORY_POOL*Constants.INITIAL_MEMORY_PRICE,cvx.longValue());
116120
}
117121

122+
@Test
123+
public void testInitEncoding() throws BadFormatException {
124+
Blob b=Format.encodeMultiCell(STATE, true);
125+
126+
State s=Format.decodeMultiCell(b);
127+
assertEquals(STATE,s);
128+
assertEquals(STATE.getAccount(Core.CORE_ADDRESS),s.getAccount(Core.CORE_ADDRESS));
129+
assertEquals(STATE.getAccount(29),s.getAccount(29));
130+
}
131+
118132
@Test
119133
public void testInitRef() {
120134
State s=STATE;

0 commit comments

Comments
 (0)