Skip to content

Commit

Permalink
removed cpi context feature, 1 test in system-cpi-tests fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Jun 27, 2024
1 parent 252dc4d commit 4c1278e
Show file tree
Hide file tree
Showing 31 changed files with 255 additions and 130 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/light-system-programs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
- reopened
- ready_for_review

name: system-programs-psp-examples-tests
name: system-programs-examples-tests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -40,7 +40,7 @@ jobs:
include:
- program: account-compression
sub-tests: '[
"cargo-test-sbf -p account-compression-test -- --test-threads=1"
"cargo-test-sbf -p account-compression-test"
]'
- program: light-system-program
sub-tests: '[
Expand All @@ -62,6 +62,11 @@ jobs:
sub-tests: '[
"RUST_MIN_STACK=8388608 cargo-test-sbf -p e2e-test -- --nocapture --test-threads=1"
]'
- program: token-escrow-test
sub-tests: '[
"cargo test-sbf -p token-escrow -- --test-threads=1"
]'


steps:
- name: Checkout sources
Expand Down
2 changes: 1 addition & 1 deletion examples/token-escrow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"scripts": {
"lint:fix": "prettier \"*/**/*{.js,.ts}\" -w",
"lint": "prettier \"*/**/*{.js,.ts}\" --check",
"test": "cargo test-sbf --features cpi-context -p token-escrow -- --test-threads 1"
"test": "cargo test-sbf --features -p token-escrow -- --test-threads 1"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0"
Expand Down
11 changes: 5 additions & 6 deletions examples/token-escrow/programs/token-escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@ no-entrypoint = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
custom-heap = []
default = ["custom-heap", "idl-build", "cpi-context"]
default = ["custom-heap", "idl-build"]
test-sbf = []
cpi-context = []
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

[dependencies]
anchor-lang = { version="0.29.0", features = ["init-if-needed"] }
light-compressed-token = { path = "../../../../programs/compressed-token", version = "0.4.1", features = ["cpi", "cpi-context"]}
light-system-program = { path = "../../../../programs/system", version = "0.4.1", features = ["cpi", "cpi-context"]}
light-compressed-token = { path = "../../../../programs/compressed-token", version = "0.4.1", features = ["cpi"]}
light-system-program = { path = "../../../../programs/system", version = "0.4.1", features = ["cpi"]}
account-compression = { path = "../../../../programs/account-compression", version = "0.4.1", features = ["cpi"] }
light-hasher = { path = "../../../../merkle-tree/hasher", version = "0.2.1" }
light-verifier = { path = "../../../../circuit-lib/verifier", version = "0.2.1" }
light-sdk = { path = "../../../../sdk", version = "0.2.1", features = ["cpi", "cpi-context"] }
light-sdk = { path = "../../../../sdk", version = "0.2.1", features = ["cpi"] }

[target.'cfg(not(target_os = "solana"))'.dependencies]
solana-sdk = "1.18.11"

[dev-dependencies]
solana-program-test = { workspace = true }
light-test-utils = { version = "0.2.1", path = "../../../../test-utils", features = ["cpi-context"] }
light-test-utils = { version = "0.2.1", path = "../../../../test-utils" }
reqwest = "0.12"
tokio = "1.36.0"
light-prover-client = { path = "../../../../circuit-lib/light-prover-client", version = "0.2.1" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ fn cpi_compressed_pda_transfer<'info>(
proof: CompressedProof,
new_address_params: NewAddressParamsPacked,
compressed_pda: OutputCompressedAccountWithPackedContext,
cpi_context: CompressedCpiContext,
mut cpi_context: CompressedCpiContext,
bump: u8,
) -> Result<()> {
// Create CPI signer seed
let bump_seed = &[bump];
let signer_key_bytes = ctx.accounts.signer.key.to_bytes();
let signer_seeds = [&b"escrow"[..], &signer_key_bytes[..], bump_seed];

cpi_context.first_set_context = false;
msg!(
"cpi context account index: {}",
cpi_context.first_set_context
);
// Create inputs struct
let inputs_struct = create_cpi_inputs_for_new_address(
proof,
Expand Down Expand Up @@ -184,6 +188,7 @@ pub fn cpi_compressed_token_transfer_pda<'info>(
mut cpi_context: CompressedCpiContext,
) -> Result<()> {
cpi_context.set_context = true;
// cpi_context.first_set_context = true;

let inputs_struct = CompressedTokenInstructionDataTransfer {
proof: Some(proof),
Expand All @@ -198,7 +203,7 @@ pub fn cpi_compressed_token_transfer_pda<'info>(

let mut inputs = Vec::new();
CompressedTokenInstructionDataTransfer::serialize(&inputs_struct, &mut inputs).unwrap();

msg!("token transfer fee payer: {:?}", ctx.accounts.signer.key());
let cpi_accounts = light_compressed_token::cpi::accounts::TransferInstruction {
fee_payer: ctx.accounts.signer.to_account_info(),
authority: ctx.accounts.signer.to_account_info(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn create_escrow_instruction(
new_address_params: new_address_params[0],
cpi_context: CompressedCpiContext {
set_context: false,
first_set_context: true,
cpi_context_account_index,
},
bump: token_owner_pda.1,
Expand Down Expand Up @@ -185,6 +186,7 @@ pub fn create_withdrawal_instruction(
};
let cpi_context = CompressedCpiContext {
set_context: false,
first_set_context: true,
cpi_context_account_index,
};
let input_compressed_pda = PackedInputCompressedPda {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ fn cpi_compressed_pda_withdrawal<'info>(
proof: CompressedProof,
old_state: PackedCompressedAccountWithMerkleContext,
compressed_pda: OutputCompressedAccountWithPackedContext,
cpi_context: CompressedCpiContext,
mut cpi_context: CompressedCpiContext,
bump: u8,
) -> Result<()> {
// Create CPI signer seed
let bump_seed = &[bump];
let signer_key_bytes = ctx.accounts.signer.key.to_bytes();
let signer_seeds = [&b"escrow"[..], &signer_key_bytes[..], bump_seed];
cpi_context.first_set_context = false;

// Create CPI inputs
let inputs_struct = InstructionDataInvokeCpi {
Expand All @@ -152,6 +153,7 @@ fn cpi_compressed_pda_withdrawal<'info>(

Ok(())
}

// TODO: test with delegate (is disabled right now)
#[inline(never)]
pub fn cpi_compressed_token_withdrawal<'info>(
Expand Down
30 changes: 30 additions & 0 deletions js/compressed-token/src/idl/light_compressed_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,25 @@ export type LightCompressedToken = {
fields: [
{
name: 'setContext';
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
];
type: 'bool';
},
{
name: 'firstSetContext';
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
];
type: 'bool';
},
{
name: 'cpiContextAccountIndex';
docs: [
'Index of cpi context account in remaining accounts.',
];
type: 'u8';
},
];
Expand Down Expand Up @@ -2197,10 +2212,25 @@ export const IDL: LightCompressedToken = {
fields: [
{
name: 'setContext',
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
],
type: 'bool',
},
{
name: 'firstSetContext',
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
],
type: 'bool',
},
{
name: 'cpiContextAccountIndex',
docs: [
'Index of cpi context account in remaining accounts.',
],
type: 'u8',
},
],
Expand Down
30 changes: 30 additions & 0 deletions js/stateless.js/src/idls/light_compressed_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,25 @@ export type LightCompressedToken = {
fields: [
{
name: 'setContext';
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
];
type: 'bool';
},
{
name: 'firstSetContext';
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
];
type: 'bool';
},
{
name: 'cpiContextAccountIndex';
docs: [
'Index of cpi context account in remaining accounts.',
];
type: 'u8';
},
];
Expand Down Expand Up @@ -2197,10 +2212,25 @@ export const IDL: LightCompressedToken = {
fields: [
{
name: 'setContext',
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
],
type: 'bool',
},
{
name: 'firstSetContext',
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
],
type: 'bool',
},
{
name: 'cpiContextAccountIndex',
docs: [
'Index of cpi context account in remaining accounts.',
],
type: 'u8',
},
],
Expand Down
48 changes: 48 additions & 0 deletions js/stateless.js/src/idls/light_system_program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ export type LightSystemProgram = {
type: {
kind: 'struct';
fields: [
{
name: 'feePayer';
type: 'publicKey';
},
{
name: 'associatedMerkleTree';
type: 'publicKey';
Expand Down Expand Up @@ -604,10 +608,25 @@ export type LightSystemProgram = {
fields: [
{
name: 'setContext';
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
];
type: 'bool';
},
{
name: 'firstSetContext';
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
];
type: 'bool';
},
{
name: 'cpiContextAccountIndex';
docs: [
'Index of cpi context account in remaining accounts.',
];
type: 'u8';
},
];
Expand Down Expand Up @@ -953,6 +972,11 @@ export type LightSystemProgram = {
name: 'InstructionNotCallable';
msg: 'The instruction is not callable';
},
{
code: 6029;
name: 'CpiContextFeePayerMismatch';
msg: 'CpiContextFeePayerMismatch';
},
];
};

Expand Down Expand Up @@ -1245,6 +1269,10 @@ export const IDL: LightSystemProgram = {
type: {
kind: 'struct',
fields: [
{
name: 'feePayer',
type: 'publicKey',
},
{
name: 'associatedMerkleTree',
type: 'publicKey',
Expand Down Expand Up @@ -1566,10 +1594,25 @@ export const IDL: LightSystemProgram = {
fields: [
{
name: 'setContext',
docs: [
'Is set by the program that is invoking the CPI to signal that is should',
'set the cpi context.',
],
type: 'bool',
},
{
name: 'firstSetContext',
docs: [
'Is set to wipe the cpi context since someone could have set it before',
'with unrelated data.',
],
type: 'bool',
},
{
name: 'cpiContextAccountIndex',
docs: [
'Index of cpi context account in remaining accounts.',
],
type: 'u8',
},
],
Expand Down Expand Up @@ -1916,5 +1959,10 @@ export const IDL: LightSystemProgram = {
name: 'InstructionNotCallable',
msg: 'The instruction is not callable',
},
{
code: 6029,
name: 'CpiContextFeePayerMismatch',
msg: 'CpiContextFeePayerMismatch',
},
],
};
2 changes: 1 addition & 1 deletion programs/compressed-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ no-log-ix-name = []
cpi = ["no-entrypoint"]
custom-heap = ["light-heap"]
mem-profiling = []
default = ["custom-heap", "idl-build", "cpi-context"]
default = ["custom-heap", "idl-build"]
test-sbf = []
bench-sbf = []
cpi-context = []
Expand Down
8 changes: 1 addition & 7 deletions programs/compressed-token/src/process_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,7 @@ pub fn cpi_execute_compressed_transaction_transfer<

let signer_seeds = get_cpi_signer_seeds();
let signer_seeds_ref = &[&signer_seeds[..]];
#[cfg(not(feature = "cpi-context"))]
if cpi_context.is_some() {
unimplemented!("cpi-context feature is not enabled");
}
#[cfg(not(feature = "cpi-context"))]
let cpi_context_account = None;
#[cfg(feature = "cpi-context")]

let cpi_context_account = cpi_context.map(|cpi_context| {
remaining_accounts[cpi_context.cpi_context_account_index as usize].to_account_info()
});
Expand Down
6 changes: 3 additions & 3 deletions programs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"push-idls": "../scripts/push-stateless-js-idls.sh && ../scripts/push-compressed-token-idl.sh",
"build": "anchor build",
"build-idls": "anchor build && pnpm build-system && pnpm build-compressed-token && pnpm push-idls",
"build-system": "anchor build --program-name light_system_program -- --features cpi-context idl-build custom-heap",
"build-compressed-token": "anchor build --program-name light_compressed_token -- --features cpi-context idl-build custom-heap",
"build-system": "anchor build --program-name light_system_program -- --features idl-build custom-heap",
"build-compressed-token": "anchor build --program-name light_compressed_token -- --features idl-build custom-heap",
"test": "pnpm test-account-compression && pnpm test-system && pnpm test-compressed-token && pnpm test-registry",
"test-account-compression": "cargo-test-sbf -p account-compression-test -- --test-threads=1",
"test-system": "cargo test-sbf -p system-test -- --test-threads=1",
"test-compressed-token": "cargo test-sbf -p compressed-token-test -- --test-threads=1",
"test-registry": "cargo-test-sbf -p registry-test -- --test-threads=1",
"token-escrow": "cargo-test-sbf -p token-escrow -- --test-threads=1 --features cpi-context idl-build",
"token-escrow": "cargo-test-sbf -p token-escrow -- --test-threads=1 --features idl-build",
"program-owned-account-test": "cargo-test-sbf -p program-owned-account-test -- --test-threads=1",
"random-e2e-test": "RUST_MIN_STACK=8388608 cargo-test-sbf -p e2e-test -- --nocapture --test-threads=1"
},
Expand Down
Loading

0 comments on commit 4c1278e

Please sign in to comment.