Skip to content

Commit

Permalink
Fixes for Solidity/Solang (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyoung authored Oct 24, 2023
1 parent e0d0df4 commit 749c45a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ solana-cli-config = "1.16"
solana-faucet = "1.16"
solana-program = "1.16"
solana-sdk = "1.16"
solang-parser = "=0.3.2"
# Pin solang-parser because it may break in a backwards incompatible way in minor versions
solang-parser = "=0.3.3"
syn = { version = "1.0.60", features = ["full", "extra-traits"] }
tar = "0.4.35"
toml = "0.7.6"
Expand Down
20 changes: 8 additions & 12 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,7 @@ fn init(
}

let mut localnet = BTreeMap::new();
let program_id = if solidity {
solidity_template::default_program_id()
} else {
rust_template::get_or_create_program_id(&rust_name)
};
let program_id = rust_template::get_or_create_program_id(&rust_name);
localnet.insert(
rust_name,
ProgramDeployment {
Expand Down Expand Up @@ -947,16 +943,16 @@ fn new(
return Err(anyhow!("Program already exists"));
}

if solidity {
solidity_template::create_program(&name)?;
} else {
rust_template::create_program(&name, template)?;
}

programs.insert(
name.clone(),
ProgramDeployment {
address: if solidity {
solidity_template::create_program(&name)?;
solidity_template::default_program_id()
} else {
rust_template::create_program(&name, template)?;
rust_template::get_or_create_program_id(&name)
},
address: rust_template::get_or_create_program_id(&name),
path: None,
idl: None,
},
Expand Down
28 changes: 14 additions & 14 deletions cli/src/solidity_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{config::ProgramWorkspace, create_files};
use anchor_syn::idl::types::Idl;
use anyhow::Result;
use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase};
use solana_sdk::pubkey::Pubkey;
use std::fmt::Write;
use std::path::Path;

Expand All @@ -16,12 +15,6 @@ pub fn create_program(name: &str) -> Result<()> {
create_files(&files)
}

pub fn default_program_id() -> Pubkey {
"F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC"
.parse()
.unwrap()
}

pub fn idl_ts(idl: &Idl) -> Result<String> {
let mut idl = idl.clone();
for acc in idl.accounts.iter_mut() {
Expand Down Expand Up @@ -128,7 +121,6 @@ module.exports = async function (provider) {
pub fn solidity(name: &str) -> String {
format!(
r#"
@program_id("{}")
contract {} {{
bool private value = true;
Expand All @@ -150,7 +142,6 @@ contract {} {{
}}
}}
"#,
default_program_id(),
name.to_snake_case(),
)
}
Expand All @@ -166,20 +157,30 @@ describe("{}", () => {{
it("Is initialized!", async () => {{
// Add your test here.
const program = anchor.workspace.{};
const tx = await program.methods.initialize().rpc();
const dataAccount = anchor.web3.Keypair.generate();
const tx = await program.methods
.new()
.accounts({{ dataAccount: dataAccount.publicKey }})
.signers([dataAccount])
.rpc();
console.log("Your transaction signature", tx);
const val1 = await program.methods.get()
const val1 = await program.methods
.get()
.accounts({{ dataAccount: dataAccount.publicKey }})
.view();
console.log("state", val1);
await program.methods.flip()
await program.methods
.flip()
.accounts({{ dataAccount: dataAccount.publicKey }})
.rpc();
const val2 = await program.methods.get()
const val2 = await program.methods
.get()
.accounts({{ dataAccount: dataAccount.publicKey }})
.view();
Expand Down Expand Up @@ -312,7 +313,6 @@ describe("{}", () => {{
anchor.setProvider(provider);
const dataAccount = anchor.web3.Keypair.generate();
const wallet = provider.wallet;
const program = anchor.workspace.{} as Program<{}>;
Expand Down
1 change: 0 additions & 1 deletion tests/solang/solidity/flipper.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
contract flipper {
bool private value = true;

Expand Down
4 changes: 2 additions & 2 deletions ts/packages/anchor/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class AnchorProvider implements Provider {

let result: RpcResponseAndContext<SimulatedTransactionResponse>;
if (isVersionedTransaction(tx)) {
if (signers) {
if (signers && signers.length > 0) {
tx.sign(signers);
tx = await this.wallet.signTransaction(tx);
}
Expand All @@ -307,7 +307,7 @@ export class AnchorProvider implements Provider {
tx.feePayer = tx.feePayer || this.wallet.publicKey;
tx.recentBlockhash = recentBlockhash;

if (signers) {
if (signers && signers.length > 0) {
tx = await this.wallet.signTransaction(tx);
}
result = await simulateTransaction(
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/anchor/src/utils/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function simulateTransaction(
};
}

if (signers) {
if (signers && signers.length > 0) {
config.sigVerify = true;
}

Expand Down

1 comment on commit 749c45a

@vercel
Copy link

@vercel vercel bot commented on 749c45a Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-docs-git-master-200ms.vercel.app
anchor-lang.com

Please sign in to comment.