Files
SHiNE-server/SHiNE-server/shine-server-solana-users-sync/src/test/java/sync/codec/ShineUsersCodecLegacyV10Test.java
T

106 lines
3.1 KiB
Java

package sync.codec;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import static org.junit.jupiter.api.Assertions.*;
class ShineUsersCodecLegacyV10Test {
@Test
void rejectsLegacyServerPdaLayout() {
byte[] raw = buildLegacyServerPda();
assertThrows(IllegalArgumentException.class, () -> ShineUsersCodec.parseUserPdaAccount(
"legacy-pda", 123L, Base64.getEncoder().encodeToString(raw), "legacy-tx"
));
}
private static byte[] buildLegacyServerPda() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
bytes(out, "SHiNE".getBytes(StandardCharsets.UTF_8));
u8(out, 1);
u8(out, 0);
u16(out, 0); // record_len patch later
u64(out, 1_700_000_000_000L);
u64(out, 1_700_000_001_000L);
u32(out, 3);
bytes(out, repeat(0x11, 32));
str(out, "legacy_server");
u8(out, 7); // recovery, root, client, blockchain, server, access, trusted
u8(out, 0); u8(out, 0); bytes(out, repeat(0x21, 32));
u8(out, 1); u8(out, 0); bytes(out, repeat(0x22, 32));
u8(out, 2); u8(out, 0); bytes(out, repeat(0x23, 32));
u8(out, 3); u8(out, 0);
u8(out, 1);
u8(out, 1);
str(out, "legacy_server-001");
bytes(out, repeat(0x24, 32));
u64(out, 100_000L);
u64(out, 12_345L);
u32(out, 7);
bytes(out, repeat(0x25, 32));
bytes(out, repeat(0x26, 64));
u8(out, 1);
str(out, "legacy-arweave-tx");
u8(out, 30); u8(out, 0);
u8(out, 1);
u8(out, 1);
u8(out, 0);
str(out, "wss://legacy.example/ws");
u8(out, 1);
str(out, "sync-old");
u8(out, 40); u8(out, 0);
u8(out, 1);
str(out, "access-old");
u8(out, 70); u8(out, 0); u8(out, 2);
bytes(out, repeat(0x27, 64));
byte[] record = out.toByteArray();
record[7] = (byte) (record.length & 0xff);
record[8] = (byte) ((record.length >>> 8) & 0xff);
return record;
}
private static byte[] repeat(int value, int count) {
byte[] bytes = new byte[count];
java.util.Arrays.fill(bytes, (byte) value);
return bytes;
}
private static void str(ByteArrayOutputStream out, String value) {
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
u8(out, bytes.length);
bytes(out, bytes);
}
private static void bytes(ByteArrayOutputStream out, byte[] value) {
out.writeBytes(value);
}
private static void u8(ByteArrayOutputStream out, long value) {
out.write((int) value & 0xff);
}
private static void u16(ByteArrayOutputStream out, long value) {
u8(out, value);
u8(out, value >>> 8);
}
private static void u32(ByteArrayOutputStream out, long value) {
for (int i = 0; i < 4; i++) u8(out, value >>> (8 * i));
}
private static void u64(ByteArrayOutputStream out, long value) {
for (int i = 0; i < 8; i++) u8(out, value >>> (8 * i));
}
}