Fixes for Solidity/Solang (#2677)
This commit is contained in:
parent
e0d0df4ab5
commit
749c45a2d9
|
@ -4528,9 +4528,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "solang-parser"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cb9fa2fa2fa6837be8a2495486ff92e3ffe68a99b6eeba288e139efdd842457"
|
||||
checksum = "c425ce1c59f4b154717592f0bdf4715c3a1d55058883622d3157e1f0908a5b26"
|
||||
dependencies = [
|
||||
"itertools 0.11.0",
|
||||
"lalrpop",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -128,7 +121,6 @@ module.exports = async function (provider) {
|
|||
pub fn solidity(name: &str) -> String {
|
||||
format!(
|
||||
r#"
|
||||
@program_id("{}")
|
||||
contract {} {{
|
||||
bool private value = true;
|
||||
|
||||
|
@ -150,7 +142,6 @@ contract {} {{
|
|||
}}
|
||||
}}
|
||||
"#,
|
||||
default_program_id(),
|
||||
name.to_snake_case(),
|
||||
)
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -312,7 +313,6 @@ describe("{}", () => {{
|
|||
anchor.setProvider(provider);
|
||||
|
||||
const dataAccount = anchor.web3.Keypair.generate();
|
||||
const wallet = provider.wallet;
|
||||
|
||||
const program = anchor.workspace.{} as Program<{}>;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
|
||||
contract flipper {
|
||||
bool private value = true;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
|
|
@ -184,7 +184,7 @@ export async function simulateTransaction(
|
|||
};
|
||||
}
|
||||
|
||||
if (signers) {
|
||||
if (signers && signers.length > 0) {
|
||||
config.sigVerify = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue