Skip to content

Commit

Permalink
solana: refactor; fix various things; add tests
Browse files Browse the repository at this point in the history
Co-authored-by: gator-boi <[email protected]>
  • Loading branch information
a5-pickle and gator-boi committed Nov 7, 2023
1 parent 719d64a commit 68ffe1f
Show file tree
Hide file tree
Showing 232 changed files with 9,479 additions and 8,535 deletions.
32 changes: 31 additions & 1 deletion solana/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,34 @@ filename = "tests/accounts/registered_emitter_2.json"
### Registered Token Bridge (Ethereum) for Fork
[[test.validator.account]]
address = "DujfLgMKW71CT2W8pxknf42FT86VbcK5PjQ6LsutjWKC"
filename = "tests/accounts/fork.registered_emitter_2.json"
filename = "tests/accounts/fork.registered_emitter_2.json"

### Token Bridge Wrapped Mint (Ethereum)
[[test.validator.account]]
address = "ATdV7cKoJnw3s6kaoY2jrQAnoc3wg3PmGpHFdUuHYK67"
filename = "tests/accounts/wrapped_mint_2.json"

### Token Bridge Wrapped Asset (Ethereum)
[[test.validator.account]]
address = "CfBrfpS7cCNU5m5FtHvV7mPoURa71kT34Mf9XP8dpjmb"
filename = "tests/accounts/wrapped_asset_2.json"

### Token Bridge Wrapped Mint (Ethereum) Metadata
[[test.validator.account]]
address = "6XqcNZL4yn8X8saab9fMuJRxZFEtNyp96DCeDTkqxduY"
filename = "tests/accounts/wrapped_mint_2_metadata.json"

### Token Bridge Wrapped Mint (Ethereum) for Fork
[[test.validator.account]]
address = "CAjoti21mmQZxtdTdmrfUL7oCzA1Yqa3u6NdWvFkmqej"
filename = "tests/accounts/fork.wrapped_mint_2.json"

### Token Bridge Wrapped Asset (Ethereum) for Fork
[[test.validator.account]]
address = "CQn6Ts4su6V7upffbEthe2xsVnSxMdTC42yZWKRveXkU"
filename = "tests/accounts/fork.wrapped_asset_2.json"

### Token Bridge Wrapped Mint (Ethereum) Metadata for Fork
[[test.validator.account]]
address = "BR9RYXcjBzyKYVfze3K2SbFFS5DG78UUfUf1Peh16uPz"
filename = "tests/accounts/fork.wrapped_mint_2_metadata.json"
18 changes: 13 additions & 5 deletions solana/Cargo.lock

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

17 changes: 13 additions & 4 deletions solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,45 @@ out_mainnet=artifacts-mainnet
out_testnet=artifacts-testnet
out_localnet=artifacts-localnet

.PHONY: all clean check build test lint
.PHONY: all clean check build test lint prune_idl ci

all: check

check:
cargo check --all-features

clean:
anchor clean
rm -rf node_modules artifacts-mainnet artifacts-testnet artifacts-localnet tests/artifacts

node_modules:
npm ci

prune_idl: scripts/prune_idl_types.ts
cd scripts && npx ts-node prune_idl_types.ts

build: $(out_$(NETWORK))
$(out_$(NETWORK)):
ifdef out_$(NETWORK)
anchor build -p wormhole_core_bridge_solana --arch sbf -- --features "$(NETWORK)" -- --no-default-features
anchor build -p wormhole_token_bridge_solana --arch sbf -- --features "$(NETWORK)" -- --no-default-features
mkdir -p $(out_$(NETWORK))
cp target/deploy/*.so $(out_$(NETWORK))/
$(MAKE) prune_idl
endif

test: node_modules
cargo test
cargo test --all-features
anchor build -p wormhole_core_bridge_solana --arch sbf -- --features mainnet -- --no-default-features
anchor build -p wormhole_token_bridge_solana --arch sbf -- --features mainnet -- --no-default-features
mkdir -p tests/artifacts && cp target/deploy/*.so tests/artifacts/
anchor test --arch sbf -- --features localnet -- --no-default-features
anchor build --arch sbf -- --features localnet -- --no-default-features
$(MAKE) prune_idl
anchor test --skip-build

lint:
cargo fmt --check
cargo clippy --no-deps --all-targets -- -D warnings
cargo clippy --no-deps --all-targets --all-features -- -D warnings

ci:
DOCKER_BUILDKIT=1 docker build -f Dockerfile.ci \
Expand Down
3 changes: 1 addition & 2 deletions solana/examples/core-bridge-hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ cpi = ["no-entrypoint"]
[dependencies]
wormhole-core-bridge-solana = { path = "../../programs/core-bridge", features = ["cpi"], default-features = false }

anchor-lang = { version = "0.28.0", features = ["init-if-needed"] }
anchor-spl = "0.28.0"
anchor-lang = "0.28.0"
40 changes: 16 additions & 24 deletions solana/examples/core-bridge-hello-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::result_large_err)]

use anchor_lang::prelude::*;
use wormhole_core_bridge_solana::sdk as core_bridge_sdk;

Expand Down Expand Up @@ -30,19 +32,15 @@ pub struct PublishHelloWorld<'info> {

/// CHECK: This account is needed for the Core Bridge program.
#[account(mut)]
core_fee_collector: Option<UncheckedAccount<'info>>,
core_fee_collector: UncheckedAccount<'info>,

system_program: Program<'info, System>,
core_bridge_program: Program<'info, core_bridge_sdk::cpi::CoreBridge>,
}

impl<'info> core_bridge_sdk::cpi::InvokeCoreBridge<'info> for PublishHelloWorld<'info> {
fn core_bridge_program(&self) -> AccountInfo<'info> {
self.core_bridge_program.to_account_info()
}
}

impl<'info> core_bridge_sdk::cpi::CreateAccount<'info> for PublishHelloWorld<'info> {
impl<'info> core_bridge_sdk::cpi::system_program::CreateAccount<'info>
for PublishHelloWorld<'info>
{
fn payer(&self) -> AccountInfo<'info> {
self.payer.to_account_info()
}
Expand All @@ -53,30 +51,24 @@ impl<'info> core_bridge_sdk::cpi::CreateAccount<'info> for PublishHelloWorld<'in
}

impl<'info> core_bridge_sdk::cpi::PublishMessage<'info> for PublishHelloWorld<'info> {
fn core_bridge_config(&self) -> AccountInfo<'info> {
self.core_bridge_config.to_account_info()
fn core_bridge_program(&self) -> AccountInfo<'info> {
self.core_bridge_program.to_account_info()
}

fn core_emitter(&self) -> Option<AccountInfo<'info>> {
None
fn core_bridge_config(&self) -> AccountInfo<'info> {
self.core_bridge_config.to_account_info()
}

fn core_emitter_authority(&self) -> Option<AccountInfo<'info>> {
Some(self.core_program_emitter.to_account_info())
fn core_emitter_authority(&self) -> AccountInfo<'info> {
self.core_program_emitter.to_account_info()
}

fn core_emitter_sequence(&self) -> AccountInfo<'info> {
self.core_emitter_sequence.to_account_info()
}

fn core_fee_collector(&self) -> Option<AccountInfo<'info>> {
self.core_fee_collector
.as_ref()
.map(|acc| acc.to_account_info())
}

fn core_message(&self) -> AccountInfo<'info> {
self.core_message.to_account_info()
Some(self.core_fee_collector.to_account_info())
}
}

Expand All @@ -90,17 +82,17 @@ pub mod core_bridge_hello_world {

core_bridge_sdk::cpi::publish_message(
ctx.accounts,
&ctx.accounts.core_message,
core_bridge_sdk::cpi::PublishMessageDirective::ProgramMessage {
program_id: crate::ID,
nonce,
payload,
commitment: core_bridge_sdk::types::Commitment::Finalized,
},
&[
Some(&[&[
core_bridge_sdk::PROGRAM_EMITTER_SEED_PREFIX,
&[ctx.bumps["core_program_emitter"]],
],
None,
]]),
)
}
}
26 changes: 26 additions & 0 deletions solana/examples/token-bridge-hello-world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "token-bridge-hello-world"
description = "Token Bridge Hello World"
version = "0.0.0"
edition = "2021"
authors = ["W7"]
license = "Apache-2.0"
homepage = "https://docs.rs/wormhole-token-bridge-solana"
repository = "https://github.com/wormhole-foundation/wormhole"

[lib]
crate-type = ["cdylib", "lib"]

[features]
default = ["localnet"]
localnet = ["wormhole-token-bridge-solana/localnet"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]

[dependencies]
wormhole-token-bridge-solana = { path = "../../programs/token-bridge", features = ["cpi"], default-features = false }

anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
Loading

0 comments on commit 68ffe1f

Please sign in to comment.