Skip to content

Commit

Permalink
Do not overwrite accounts signer and writer field
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Steuernagel <[email protected]>
  • Loading branch information
LucasSte committed Jul 24, 2023
1 parent 76c0109 commit ab62a34
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
62 changes: 62 additions & 0 deletions src/abi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2333,3 +2333,65 @@ contract BeingBuilt {
]
);
}

#[test]
fn modifier() {
let src1 = r#"
import "solana";
@program_id("CU8sqXecq7pxweQnJq6CARonEApGN2DXcv9ukRBRgnRf")
contract starter {
bool private value = true;
modifier test_modifier() {
print("modifier");
_;
}
@payer(payer)
constructor() {
print("Hello, World!");
}
function flip() public test_modifier {
value = !value;
}
function get() public view returns (bool) {
return value;
}
}
"#;

let src2 = r#"
import "solana";
@program_id("CU8sqXecq7pxweQnJq6CARonEApGN2DXcv9ukRBRgnRf")
contract starter {
bool private value = true;
@payer(payer)
constructor() {
print("Hello, World!");
}
function flip() public {
value = !value;
}
function get() public view returns (bool) {
return value;
}
}
"#;

let mut ns1 = generate_namespace(src1);
codegen(&mut ns1, &Options::default());
let idl1 = generate_anchor_idl(0, &ns1, "0.1.0");

let mut ns2 = generate_namespace(src2);
codegen(&mut ns2, &Options::default());
let idl2 = generate_anchor_idl(0, &ns2, "0.1.0");

assert_eq!(idl1, idl2);
}
11 changes: 9 additions & 2 deletions src/codegen/solana_accounts/account_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ struct RecurseData<'a> {
impl RecurseData<'_> {
/// Add an account to the function's indexmap
fn add_account(&mut self, account_name: String, account: SolanaAccount) {
let (is_signer, is_writer) = self.functions[self.ast_no]
.solana_accounts
.borrow()
.get(&account_name)
.map(|acc| (acc.is_signer, acc.is_writer))
.unwrap_or((false, false));

if self.functions[self.ast_no]
.solana_accounts
.borrow_mut()
.insert(
account_name,
SolanaAccount {
loc: account.loc,
is_signer: account.is_signer,
is_writer: account.is_writer,
is_signer: account.is_signer || is_signer,
is_writer: account.is_writer || is_writer,
generated: true,
},
)
Expand Down

0 comments on commit ab62a34

Please sign in to comment.