Skip to content

Commit

Permalink
Bump anchor and other dependencies (hyperledger#1570)
Browse files Browse the repository at this point in the history
Update all the crates which can be updated easily.

Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Oct 20, 2023
1 parent 6b04c23 commit b299eae
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 82 deletions.
39 changes: 20 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ serde = "1.0"
serde_derive = { version = "1.0" }
inkwell = { version = "0.2.0", features = ["target-webassembly", "no-libffi-linking", "llvm15-0"], optional = true }
blake2-rfc = "0.2.18"
handlebars = "4.3"
contract-metadata = "3.0"
handlebars = "4.4"
contract-metadata = "3.2"
semver = { version = "1.0", features = ["serde"] }
tempfile = "3.4"
tempfile = "3.8"
libc = { version = "0.2", optional = true }
tower-lsp = "0.20"
tokio = { version = "1.27", features = ["rt", "io-std", "macros"] }
Expand All @@ -45,22 +45,22 @@ funty = "2.0"
itertools = "0.11"
num-rational = "0.4"
indexmap = "2.0"
once_cell = "1.17"
solang-parser = { path = "solang-parser", version = "0.3.1" }
once_cell = "1.18"
solang-parser = { path = "solang-parser", version = "0.3.2" }
codespan-reporting = "0.11"
phf = { version = "0.11", features = ["macros"] }
rust-lapper = "1.1"
anchor-syn = { version = "0.28.0", features = ["idl"] }
anchor-syn = { version = "0.29.0", features = ["idl-build"] }
convert_case = "0.6"
parse-display = "0.8.0"
parity-scale-codec = "3.4"
ink_env = "4.2.0"
ink_metadata = "4.2.0"
scale-info = "2.4"
petgraph = "0.6.3"
parse-display = "0.8"
parity-scale-codec = "3.6"
ink_env = "4.3.0"
ink_metadata = "4.3.0"
scale-info = "2.9"
petgraph = "0.6"
wasmparser = "0.110.0"
wasm-encoder = "0.31"
toml = "0.7"
toml = "0.8"
wasm-opt = { version = "0.112.0", optional = true }
contract-build = { version = "3.0.1", optional = true }
primitive-types = { version = "0.12", features = ["codec"] }
Expand All @@ -72,18 +72,19 @@ forge-fmt = "0.2.0"
num-derive = "0.4"
wasmi = "0.31"
# solana_rbpf makes api changes in patch versions
solana_rbpf = "=0.6.0"
byteorder = "1.4"
solana_rbpf = "=0.6.1"
byteorder = "1.5"
assert_cmd = "2.0"
bincode = "1.3"
ed25519-dalek = { version = "2", features = ["rand_core"] }
path-slash = "0.2"
pretty_assertions = "1.3"
pretty_assertions = "1.4"
byte-slice-cast = "1.2"
borsh = "0.10"
borsh = "1.1"
borsh-derive = "1.1"
rayon = "1"
walkdir = "2.3.3"
ink_primitives = "4.2.0"
walkdir = "2.4"
ink_primitives = "4.3.0"
wasm_host_attr = { path = "tests/wasm_host_attr" }
num-bigint = { version = "0.4", features = ["rand", "serde"]}

Expand Down
2 changes: 1 addition & 1 deletion integration/anchor/programs/anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.28.0"
anchor-lang = "0.29.0"
solana-program = "1.16.1"
15 changes: 15 additions & 0 deletions integration/anchor/programs/anchor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ pub mod anchor {
})
}

pub fn test_event(_ctx: Context<State>) -> Result<()> {
emit!(MyEvent {
data: 6,
label: "bye".to_string(),
});
Ok(())
}

pub fn multi_dimensional(
_ctx: Context<NoAccountsNeeded>,
arr: [[u16; 3]; 4],
Expand Down Expand Up @@ -181,3 +189,10 @@ pub struct State<'info> {
#[account()]
pub my_account: Account<'info, MyAccount>,
}

#[event]
pub struct MyEvent {
pub data: i64,
#[index]
pub label: String,
}
4 changes: 4 additions & 0 deletions integration/anchor/tests/call_anchor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ contract call_anchor {
require(ret8[1][2] == 8000, "array 2");
require(ret8[2][0] == 3000, "array 3");
}

function test_event() public {
emit MyEvent({data: 102, label: "yadayada" });
}
}
20 changes: 19 additions & 1 deletion integration/anchor/tests/call_anchor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect';
import { AnchorProvider, Program } from '@coral-xyz/anchor';
import {
PublicKey, AccountMeta,
Keypair, Signer,
Keypair,
Connection,
LAMPORTS_PER_SOL,
BpfLoader, Transaction,
Expand Down Expand Up @@ -69,6 +69,24 @@ describe('Call Anchor program from Solidity via IDL', () => {
.remainingAccounts(remainingAccounts)
.signers([data, payer])
.rpc();

let seen = false;

const listenId = program.addEventListener("MyEvent", (ev) => {
expect(ev.data.toNumber()).toBe(102);
expect(ev.label).toBe("yadayada");
seen = true;
});

await program.methods.testEvent()
.accounts({
dataAccount: storage.publicKey,
})
.rpc();

program.removeEventListener(listenId);

expect(seen).toBe(true);
});
});

Expand Down
3 changes: 1 addition & 2 deletions solang-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ phf = { version = "0.11", features = ["macros"] }
unicode-xid = "0.2"
itertools = "0.11"
thiserror = "1.0"

serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
walkdir = "2.3.3"
walkdir = "2.4"
regex = "1"
pretty_assertions = "1.3"

Expand Down
6 changes: 5 additions & 1 deletion src/abi/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::sema::ast::{
ArrayLength, Contract, Function, Namespace, Parameter, StructDecl, StructType, Tag, Type,
};
use anchor_syn::idl::{
use anchor_syn::idl::types::{
Idl, IdlAccount, IdlAccountItem, IdlEnumVariant, IdlEvent, IdlEventField, IdlField,
IdlInstruction, IdlType, IdlTypeDefinition, IdlTypeDefinitionTy,
};
Expand Down Expand Up @@ -243,6 +243,7 @@ impl TypeManager<'_> {
func.name
)]),
ty: IdlTypeDefinitionTy::Struct { fields },
generics: None,
});

IdlType::Defined(name)
Expand Down Expand Up @@ -313,6 +314,7 @@ impl TypeManager<'_> {
name,
docs,
ty: IdlTypeDefinitionTy::Struct { fields },
generics: None,
});
}

Expand All @@ -337,6 +339,7 @@ impl TypeManager<'_> {
name,
docs: item.docs,
ty: item.ty,
generics: None,
});
}

Expand Down Expand Up @@ -372,6 +375,7 @@ impl TypeManager<'_> {
name,
docs,
ty: IdlTypeDefinitionTy::Enum { variants },
generics: None,
});
}

Expand Down
35 changes: 24 additions & 11 deletions src/abi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::codegen::{codegen, Options};
use crate::file_resolver::FileResolver;
use crate::sema::ast::Namespace;
use crate::{codegen, parse_and_resolve, Target};
use anchor_syn::idl::{
use anchor_syn::idl::types::{
IdlAccount, IdlAccountItem, IdlEnumVariant, IdlEvent, IdlEventField, IdlField, IdlType,
IdlTypeDefinition, IdlTypeDefinitionTy,
};
Expand Down Expand Up @@ -311,7 +311,8 @@ fn instructions_and_types() {
ty: IdlType::String,
}
]
}
},
generics: None
}
);

Expand Down Expand Up @@ -408,7 +409,8 @@ contract caller {
fields: None,
}
]
}
},
generics: None
}
);

Expand Down Expand Up @@ -664,6 +666,7 @@ contract Testing {
}
],
},
generics: None
}
);
}
Expand Down Expand Up @@ -765,7 +768,8 @@ contract Testing {
ty: IdlType::U64
}
]
}
},
generics: None
}
);

Expand All @@ -789,7 +793,8 @@ contract Testing {
ty: IdlType::I32
}
]
}
},
generics: None
}
);
}
Expand Down Expand Up @@ -832,6 +837,7 @@ fn name_collision() {
ty: IdlType::String,
}]
},
generics: None
}
);

Expand All @@ -855,7 +861,8 @@ fn name_collision() {
ty: IdlType::U64
}
]
}
},
generics: None
}
);

Expand All @@ -879,7 +886,8 @@ fn name_collision() {
ty: IdlType::I32
}
]
}
},
generics: None
}
);
}
Expand Down Expand Up @@ -926,6 +934,7 @@ fn double_name_collision() {
ty: IdlType::String,
}]
},
generics: None
}
);

Expand All @@ -940,7 +949,8 @@ fn double_name_collision() {
docs: None,
ty: IdlType::Bytes
},]
}
},
generics: None
}
);

Expand All @@ -964,7 +974,8 @@ fn double_name_collision() {
ty: IdlType::U64
}
]
}
},
generics: None
}
);

Expand All @@ -988,7 +999,8 @@ fn double_name_collision() {
ty: IdlType::I32
}
]
}
},
generics: None
}
);
}
Expand Down Expand Up @@ -1054,7 +1066,8 @@ fn deduplication() {
ty: IdlType::PublicKey
}
]
}
},
generics: None
}
);

Expand Down
9 changes: 6 additions & 3 deletions src/bin/idl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::cli::IdlCommand;
use anchor_syn::idl::{Idl, IdlAccountItem, IdlInstruction, IdlType, IdlTypeDefinitionTy};
use anchor_syn::idl::types::{Idl, IdlAccountItem, IdlInstruction, IdlType, IdlTypeDefinitionTy};
use itertools::Itertools;
use serde_json::Value as JsonValue;
use solang::abi::anchor::discriminator;
Expand Down Expand Up @@ -176,7 +176,7 @@ fn write_solidity(idl: &Idl, mut f: File) -> Result<(), std::io::Error> {

let name = &ty_names.iter().find(|e| *e.0 == event.name).unwrap().1;

writeln!(f, "event {name} {{")?;
writeln!(f, "event {name} (")?;
let mut iter = event.fields.iter().enumerate();
let mut next = iter.next();
while let Some((no, e)) = next {
Expand All @@ -191,7 +191,7 @@ fn write_solidity(idl: &Idl, mut f: File) -> Result<(), std::io::Error> {
if next.is_some() { "," } else { "" }
)?;
}
writeln!(f, "}}")?;
writeln!(f, ");")?;
} else {
eprintln!(
"event {} has fields of type {} which is not supported on Solidity",
Expand Down Expand Up @@ -367,6 +367,9 @@ fn idltype_to_solidity(ty: &IdlType, ty_names: &[(String, String)]) -> Result<St
Ok(ty) => Ok(format!("{ty}[{size}]")),
Err(ty) => Err(format!("{ty}[{size}]")),
},
IdlType::Generic(..)
| IdlType::GenericLenArray(..)
| IdlType::DefinedWithTypeArgs { .. } => Err("generics are not supported".into()),
}
}

Expand Down
Loading

0 comments on commit b299eae

Please sign in to comment.