diff --git a/shank-idl/tests/fixtures/instructions/single_file/create_idl_instructions.json b/shank-idl/tests/fixtures/instructions/single_file/create_idl_instructions.json index 8f544ca..47c53e7 100644 --- a/shank-idl/tests/fixtures/instructions/single_file/create_idl_instructions.json +++ b/shank-idl/tests/fixtures/instructions/single_file/create_idl_instructions.json @@ -9,31 +9,41 @@ "name": "from", "isMut": true, "isSigner": true, - "desc": "Payer of the transaction" + "docs": [ + "Payer of the transaction" + ] }, { "name": "to", "isMut": true, "isSigner": false, - "desc": "The deterministically defined 'state' account being created via `create_account_with_seed`" + "docs": [ + "The deterministically defined 'state' account being created via `create_account_with_seed`" + ] }, { "name": "base", "isMut": false, "isSigner": false, - "desc": "The program-derived-address signing off on the account creation. Seeds = &[] + bump seed." + "docs": [ + "The program-derived-address signing off on the account creation. Seeds = &[] + bump seed." + ] }, { "name": "systemProgram", "isMut": false, "isSigner": false, - "desc": "The system program" + "docs": [ + "The system program" + ] }, { "name": "program", "isMut": false, "isSigner": false, - "desc": "The program whose state is being constructed" + "docs": [ + "The program whose state is being constructed" + ] } ], "args": [ @@ -74,13 +84,17 @@ "name": "buffer", "isMut": true, "isSigner": false, - "desc": "The buffer with the new idl data." + "docs": [ + "The buffer with the new idl data." + ] }, { "name": "idl", "isMut": true, "isSigner": false, - "desc": "The idl account to be updated with the buffer's data." + "docs": [ + "The idl account to be updated with the buffer's data." + ] }, { "name": "authority", diff --git a/shank-idl/tests/instructions.rs b/shank-idl/tests/instructions.rs index 265b034..bebe110 100644 --- a/shank-idl/tests/instructions.rs +++ b/shank-idl/tests/instructions.rs @@ -82,7 +82,7 @@ fn instruction_from_single_file_with_idl_instructions() { let file = fixtures_dir() .join("single_file") .join("create_idl_instructions.rs"); - let idl = parse_file(&file, &ParseIdlConfig::optional_program_address()) + let idl = parse_file(file, &ParseIdlConfig::optional_program_address()) .expect("Parsing should not fail") .expect("File contains IDL"); @@ -91,6 +91,10 @@ fn instruction_from_single_file_with_idl_instructions() { )) .unwrap(); + println!("IDL: {}", idl.try_into_json().unwrap()); + + println!("Expected: {}", expected_idl.try_into_json().unwrap()); + assert_eq!(idl, expected_idl); } diff --git a/shank-macro-impl/src/instruction/idl_instruction_attrs.rs b/shank-macro-impl/src/instruction/idl_instruction_attrs.rs index a596880..2c2c009 100644 --- a/shank-macro-impl/src/instruction/idl_instruction_attrs.rs +++ b/shank-macro-impl/src/instruction/idl_instruction_attrs.rs @@ -95,6 +95,7 @@ impl IdlInstruction { name: "from".to_string(), desc: Some("Payer of the transaction".to_string()), signer: true, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -103,6 +104,7 @@ impl IdlInstruction { name: "to".to_string(), desc: Some("The deterministically defined 'state' account being created via `create_account_with_seed`".to_string()), signer: false, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -111,6 +113,7 @@ impl IdlInstruction { name: "base".to_string(), desc: Some("The program-derived-address signing off on the account creation. Seeds = &[] + bump seed.".to_string()), signer: false, + optional_signer: false, writable: false, optional: false, }, InstructionAccount { @@ -119,6 +122,7 @@ impl IdlInstruction { name: "system_program".to_string(), desc: Some("The system program".to_string()), signer: false, + optional_signer: false, writable: false, optional: false, }, InstructionAccount { @@ -127,6 +131,7 @@ impl IdlInstruction { name: "program".to_string(), desc: Some("The program whose state is being constructed".to_string()), signer: false, + optional_signer: false, writable: false, optional: false, }]), @@ -137,6 +142,7 @@ impl IdlInstruction { name: "buffer".to_string(), desc: None, signer: false, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -145,6 +151,7 @@ impl IdlInstruction { name: "authority".to_string(), desc: None, signer: true, + optional_signer: false, writable: false, optional: false, }]), @@ -155,6 +162,7 @@ impl IdlInstruction { name: "buffer".to_string(), desc: Some("The buffer with the new idl data.".to_string()), signer: false, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -163,6 +171,7 @@ impl IdlInstruction { name: "idl".to_string(), desc: Some("The idl account to be updated with the buffer's data.".to_string()), signer: false, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -171,6 +180,7 @@ impl IdlInstruction { name: "authority".to_string(), desc: None, signer: true, + optional_signer: false, writable: false, optional: false, }]), @@ -181,6 +191,7 @@ impl IdlInstruction { name: "idl".to_string(), desc: None, signer: false, + optional_signer: false, writable: true, optional: false, }, InstructionAccount { @@ -189,6 +200,7 @@ impl IdlInstruction { name: "authority".to_string(), desc: None, signer: true, + optional_signer: false, writable: false, optional: false, }]), @@ -201,7 +213,7 @@ impl IdlInstruction { vec![( "data_len".to_string(), RustType { - ident: ident.clone(), + ident, kind: TypeKind::Primitive(Primitive::U64), context: RustTypeContext::Default, reference: crate::types::ParsedReference::Owned, @@ -212,7 +224,7 @@ impl IdlInstruction { vec![( "new_authority".to_string(), RustType { - ident: ident.clone(), + ident, kind: TypeKind::Value(Value::Custom("Pubkey".to_string())), context: RustTypeContext::Default, reference: crate::types::ParsedReference::Owned @@ -226,7 +238,7 @@ impl IdlInstruction { ident: ident.clone(), kind: TypeKind::Composite(Composite::Vec, vec![ RustType { - ident: ident.clone(), + ident, kind: TypeKind::Primitive(Primitive::U8), context: RustTypeContext::CollectionItem, reference: crate::types::ParsedReference::Owned diff --git a/shank-macro-impl/src/instruction/instruction.rs b/shank-macro-impl/src/instruction/instruction.rs index 451d56a..7e1141f 100644 --- a/shank-macro-impl/src/instruction/instruction.rs +++ b/shank-macro-impl/src/instruction/instruction.rs @@ -33,7 +33,8 @@ impl Instruction { skip_derive_attr_check: bool, ) -> ParseResult> { if skip_derive_attr_check - || get_derive_attr(&item_enum.attrs, DERIVE_INSTRUCTION_ATTR).is_some() + || get_derive_attr(&item_enum.attrs, DERIVE_INSTRUCTION_ATTR) + .is_some() { let parsed_enum = ParsedEnum::try_from(item_enum)?; Instruction::try_from(&parsed_enum).map(Some) @@ -47,7 +48,9 @@ impl TryFrom<&ParsedEnum> for Option { type Error = ParseError; fn try_from(parsed_enum: &ParsedEnum) -> ParseResult { - match get_derive_attr(&parsed_enum.attrs, DERIVE_INSTRUCTION_ATTR).map(|_| parsed_enum) { + match get_derive_attr(&parsed_enum.attrs, DERIVE_INSTRUCTION_ATTR) + .map(|_| parsed_enum) + { Some(ix_enum) => ix_enum.try_into().map(Some), None => Ok(None), } @@ -110,7 +113,12 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant { Some(_) => InstructionVariantFields::Named( fields .iter() - .map(|x| (x.ident.as_ref().unwrap().to_string(), x.rust_type.clone())) + .map(|x| { + ( + x.ident.as_ref().unwrap().to_string(), + x.rust_type.clone(), + ) + }) .collect(), ), None => InstructionVariantFields::Unnamed( @@ -126,16 +134,19 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant { let strategies: InstructionStrategies; let idl_instruction = IdlInstruction::try_from(attrs); - if idl_instruction.is_ok() { - let idl_ix = idl_instruction.unwrap(); - accounts = idl_ix.to_accounts(ident.clone()); - field_tys = idl_ix.to_instruction_fields(ident.clone()); - strategies = InstructionStrategies(HashSet::::new()); - } else { - let err = idl_instruction.unwrap_err(); - println!("{}", err); - accounts = attrs.try_into()?; - strategies = attrs.into(); + match idl_instruction { + Ok(idl_ix) => { + accounts = idl_ix.to_accounts(ident.clone()); + field_tys = idl_ix.to_instruction_fields(ident.clone()); + strategies = InstructionStrategies(HashSet::< + InstructionStrategy, + >::new()); + } + Err(err) => { + println!("{}", err); + accounts = attrs.try_into()?; + strategies = attrs.into(); + } } Ok(Self {