Skip to content

Commit

Permalink
Test javaee: add RLP test
Browse files Browse the repository at this point in the history
  • Loading branch information
hijung committed Oct 25, 2023
1 parent b732a46 commit daa9a29
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions javaee/exec/test/java/foundation/icon/ee/RLPTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2023 ICON Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package foundation.icon.ee;

import foundation.icon.ee.test.SimpleTest;
import foundation.icon.ee.types.Status;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import score.Context;
import score.ObjectReader;
import score.ObjectWriter;
import score.annotation.External;

import java.math.BigInteger;

public class RLPTest extends SimpleTest {
public static class Score {
@External(readonly=true)
public long readOverflowLenString() {
byte[] data= new byte[] {(byte)0xbb,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xfb,0x42,0x43,0x44,0x46,0x47,0x48};
ObjectReader r = Context.newByteArrayObjectReader("RLPn", data);
r.skip(0x7fffffff);

return 1;
}

@External(readonly = true)
public int zeroStrings() {
byte[] data = new byte[2_000_000_000];
ObjectReader r = Context.newByteArrayObjectReader("RLPn", data);
r.skip(2_000_000_000);
return 0;
}

@External(readonly = true)
public int writeOverflow() {
byte[] data = new byte[100_000_000];
ObjectWriter w = Context.newByteArrayObjectWriter("RLPn");
for (int i=0; i<10; i++) {
Context.println("i="+i);
w.write(data);
}
return 0;
}
}

@Test
void readOverflowLenString() {
var c = sm.mustDeploy(Score.class);
var res = c.tryInvoke("readOverflowLenString");
Assertions.assertEquals(Status.UnknownFailure, res.getStatus());
}

@Test
void zeroStrings() {
var c = sm.mustDeploy(Score.class);
sm.setStepLimit(BigInteger.valueOf(25_000_000_000L));
var res = c.tryInvoke("zeroStrings");
Assertions.assertEquals(Status.UnknownFailure, res.getStatus());
}

@Test
void writeOverflow() {
var c = sm.mustDeploy(Score.class);
sm.setStepLimit(BigInteger.valueOf(25_000_000_000L));
var res = c.tryInvoke("writeOverflow");
Assertions.assertEquals(Status.UnknownFailure, res.getStatus());
}
}

0 comments on commit daa9a29

Please sign in to comment.