Skip to content

Commit

Permalink
Add more solana.test.ts stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Mar 4, 2024
1 parent e3de6e2 commit e017083
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion node/cmd/ccq/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type (
SolanaPda struct {
Chain int `json:"chain"`
ProgramAddress string `json:"programAddress"`
// TODO: Should we make them specify seeds as well?
// As a future enhancement, we may want to specify the allowed seeds.
}

PermissionsMap map[string]*permissionEntry
Expand Down
4 changes: 2 additions & 2 deletions node/hack/query/send_req.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ func sendSolanaQueryAndGetRsp(queryRequest *query.QueryRequest, sk *ecdsa.Privat
for index := range response.PerChainResponses {
switch r := response.PerChainResponses[index].Response.(type) {
case *query.SolanaAccountQueryResponse:
logger.Info("solana query per chain response", zap.Int("index", index), zap.Any("pcr", r))
logger.Info("solana account query per chain response", zap.Int("index", index), zap.Any("pcr", r))
case *query.SolanaPdaQueryResponse:
logger.Info("solana query per chain response", zap.Int("index", index), zap.Any("pcr", r))
logger.Info("solana pda query per chain response", zap.Int("index", index), zap.Any("pcr", r))
default:
panic(fmt.Sprintf("unsupported query type, should be solana, index: %d", index))
}
Expand Down
53 changes: 53 additions & 0 deletions sdk/js-query/src/query/solana.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,57 @@ describe("solana", () => {
"57cd18b7f8a4d91a2da9ab4af05d0fbece2dcd65"
);
});
test("successful sol_pda query", async () => {
const solPdaReq = new SolanaPdaQueryRequest(
"finalized",
PDAS,
BigInt(0),
BigInt(12),
BigInt(16) // After this, things can change.
);
const nonce = 43;
const query = new PerChainQueryRequest(1, solPdaReq);
const request = new QueryRequest(nonce, [query]);
const serialized = request.serialize();
const digest = QueryRequest.digest(ENV, serialized);
const signature = sign(PRIVATE_KEY, digest);
const response = await axios.put(
QUERY_URL,
{
signature,
bytes: Buffer.from(serialized).toString("hex"),
},
{ headers: { "X-API-Key": "my_secret_key" } }
);
expect(response.status).toBe(200);

const queryResponse = QueryResponse.from(response.data.bytes);
expect(queryResponse.version).toEqual(1);
expect(queryResponse.requestChainId).toEqual(0);
expect(queryResponse.request.version).toEqual(1);
expect(queryResponse.request.requests.length).toEqual(1);
expect(queryResponse.request.requests[0].chainId).toEqual(1);
expect(queryResponse.request.requests[0].query.type()).toEqual(
ChainQueryType.SolanaPda
);

const sar = queryResponse.responses[0].response as SolanaPdaQueryResponse;
expect(sar.slotNumber).not.toEqual(BigInt(0));
expect(sar.blockTime).not.toEqual(BigInt(0));
expect(sar.results.length).toEqual(1);

expect(Buffer.from(sar.results[0].account).toString("hex")).toEqual(
"4fa9188b339cfd573a0778c5deaeeee94d4bcfb12b345bf8e417e5119dae773e"
);
expect(sar.results[0].bump).toEqual(253);
expect(sar.results[0].lamports).toEqual(BigInt(1141440));
expect(sar.results[0].rentEpoch).toEqual(BigInt(0));
expect(sar.results[0].executable).toEqual(false);
expect(Buffer.from(sar.results[0].owner).toString("hex")).toEqual(
"02c806312cbe5b79ef8aa6c17e3f423d8fdfe1d46909fb1f6cdf65ee8e2e6faa"
);
expect(Buffer.from(sar.results[0].data).toString("hex")).toEqual(
"57cd18b7f8a4d91a2da9ab4af05d0fbe"
);
});
});
1 change: 0 additions & 1 deletion sdk/js-query/src/query/solanaAccount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Buffer } from "buffer";
import base58 from "bs58";
import { BinaryWriter } from "./BinaryWriter";
import { HexString } from "./consts";
import { ChainQueryType, ChainSpecificQuery } from "./request";
import { bigIntWithDef, coalesceUint8Array } from "./utils";
import { BinaryReader } from "./BinaryReader";
Expand Down

0 comments on commit e017083

Please sign in to comment.