-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: createTransaction and tests (#11)
* fix: create-tx * chore: changeset
- Loading branch information
1 parent
0c03cb8
commit 5e0a77b
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import assert from "node:assert"; | ||
|
||
import { createTransaction } from "../core/transactions"; | ||
import { blockhash, generateKeyPairSigner, isKeyPairSigner, KeyPairSigner } from "@solana/web3.js"; | ||
|
||
describe("createTransaction", () => { | ||
let signer: KeyPairSigner; | ||
|
||
beforeAll(async () => { | ||
signer = await generateKeyPairSigner(); | ||
}); | ||
|
||
test("create a legacy transaction with a signer as the feePayer", () => { | ||
const tx = createTransaction({ | ||
version: "legacy", | ||
feePayer: signer, | ||
instructions: [], | ||
latestBlockhash: { | ||
blockhash: blockhash("GK1nopeF3P8J46dGqq4KfaEWopZU7K65F6CKQXuUdr3z"), | ||
lastValidBlockHeight: 0n, | ||
}, | ||
}); | ||
|
||
assert.equal(tx.version, "legacy"); | ||
assert.equal(tx.feePayer.address, signer.address); | ||
assert.equal(isKeyPairSigner(tx.feePayer), true); | ||
assert.equal(tx.instructions.length, 0); | ||
assert.equal(Object.hasOwn(tx, "lifetimeConstraint"), true); | ||
}); | ||
|
||
test("create a version 0 transaction with a signer as the feePayer", () => { | ||
const tx = createTransaction({ | ||
version: 0, | ||
feePayer: signer, | ||
instructions: [], | ||
}); | ||
|
||
assert.equal(tx.version, 0); | ||
assert.equal(tx.feePayer.address, signer.address); | ||
assert.equal(isKeyPairSigner(tx.feePayer), true); | ||
assert.equal(tx.instructions.length, 0); | ||
assert.equal(Object.hasOwn(tx, "lifetimeConstraint"), false); | ||
}); | ||
|
||
test("create a legacy transaction with an `Address` as the feePayer", () => { | ||
const tx = createTransaction({ | ||
version: "legacy", | ||
feePayer: signer.address, | ||
instructions: [], | ||
}); | ||
|
||
assert.equal(tx.version, "legacy"); | ||
assert.equal(tx.feePayer.address, signer.address); | ||
assert.equal(isKeyPairSigner(tx.feePayer), false); | ||
assert.equal(tx.instructions.length, 0); | ||
assert.equal(Object.hasOwn(tx, "lifetimeConstraint"), false); | ||
}); | ||
|
||
test("create a version 0 transaction with an `Address` as the feePayer", () => { | ||
const tx = createTransaction({ | ||
version: 0, | ||
feePayer: signer.address, | ||
instructions: [], | ||
latestBlockhash: { | ||
blockhash: blockhash("GK1nopeF3P8J46dGqq4KfaEWopZU7K65F6CKQXuUdr3z"), | ||
lastValidBlockHeight: 0n, | ||
}, | ||
}); | ||
|
||
assert.equal(tx.version, 0); | ||
assert.equal(tx.feePayer.address, signer.address); | ||
assert.equal(isKeyPairSigner(tx.feePayer), false); | ||
assert.equal(tx.instructions.length, 0); | ||
assert.equal(Object.hasOwn(tx, "lifetimeConstraint"), true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export * from "./rpc"; | ||
export * from "./explorer"; | ||
|
||
export type Prettify<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; |