Skip to content

Commit

Permalink
fix(svm): random seed collision tests (#788)
Browse files Browse the repository at this point in the history
* fix(svm): random seed collision tests

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: comment

Signed-off-by: Pablo Maldonado <[email protected]>

---------

Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x authored Dec 3, 2024
1 parent ebc569f commit 739e2d0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/svm/SvmSpoke.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SvmSpoke } from "../../target/types/svm_spoke";
import { evmAddressToPublicKey } from "../../src/SvmUtils";
import { assert } from "chai";
import { SlowFillLeaf } from "./utils";
import { randomBytes } from "crypto";

const provider = anchor.AnchorProvider.env();
const program = anchor.workspace.SvmSpoke as Program<SvmSpoke>;
Expand Down Expand Up @@ -41,7 +42,7 @@ const initializeState = async (
fillDeadlineBuffer: BN;
}
) => {
const actualSeed = seed || new BN(Math.floor(Math.random() * 1000000));
const actualSeed = seed || new BN(randomBytes(8).toString("hex"), 16); // Generate a random u64
const seeds = [Buffer.from("state"), actualSeed.toArrayLike(Buffer, "le", 8)];
const [state] = PublicKey.findProgramAddressSync(seeds, program.programId);
if (!initialState) {
Expand Down

0 comments on commit 739e2d0

Please sign in to comment.