This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration and compile tests, in sdk due to circularity
- Loading branch information
Tyera Eulberg
committed
Jun 27, 2020
1 parent
5ad7e63
commit f8e5062
Showing
18 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts( | ||
account(doc = "Account") | ||
)] | ||
Transfer { lamports: u64 }, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: unrecognized account detail | ||
--> $DIR/account_desc_name.rs:10:17 | ||
| | ||
10 | account(doc = "Account") | ||
| ^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts( | ||
from_account(optional, multiple, desc = "Account"), | ||
)] | ||
Transfer { lamports: u64 }, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: account cannot be optional and allow multiples | ||
--> $DIR/account_optional_multiple.rs:10:32 | ||
| | ||
10 | from_account(optional, multiple, desc = "Account"), | ||
| ^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts( | ||
from_account(writable, desc = "Account"), | ||
)] | ||
Transfer { lamports: u64 }, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: unrecognized account detail | ||
--> $DIR/account_tag.rs:10:22 | ||
| | ||
10 | from_account(writable, desc = "Account"), | ||
| ^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts( | ||
(from_account, desc = "Account"), | ||
)] | ||
Transfer { lamports: u64 }, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: unrecognized accounts format | ||
--> $DIR/accounts_list.rs:9:5 | ||
| | ||
9 | / #[accounts( | ||
10 | | (from_account, desc = "Account"), | ||
11 | | )] | ||
| |______^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts] | ||
Transfer { lamports: u64 }, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: missing accounts list | ||
--> $DIR/accounts_list_missing.rs:9:7 | ||
| | ||
9 | #[accounts] | ||
| ^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
solana_sdk::declare_id!("8dGutFWpfHymgGDV6is389USqGRqSfpGZyhBrF1VPWDg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
mod test_program; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
#[accounts( | ||
from_account(desc = "Funding account"), | ||
to_account(desc = "Recipient account") | ||
)] | ||
Transfer(u64), | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: macro does not support unnamed variant fields | ||
--> $DIR/unnamed_fields.rs:13:13 | ||
| | ||
13 | Transfer(u64), | ||
| ^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod test_program; | ||
|
||
#[test] | ||
fn compile_test() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/compile-fail/account_desc_name.rs"); | ||
t.compile_fail("tests/compile-fail/accounts_list.rs"); | ||
t.compile_fail("tests/compile-fail/accounts_list_missing.rs"); | ||
t.compile_fail("tests/compile-fail/account_optional_multiple.rs"); | ||
t.compile_fail("tests/compile-fail/account_tag.rs"); | ||
t.compile_fail("tests/compile-fail/unnamed_fields.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
use bincode::serialize; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use solana_sdk::{ | ||
instruction::{AccountMeta, Instruction}, | ||
pubkey::Pubkey, | ||
}; | ||
use solana_sdk_program_macros::instructions; | ||
|
||
#[instructions(test_program::id())] | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub enum TestInstruction { | ||
/// Transfer lamports | ||
#[accounts( | ||
from_account(SIGNER, WRITABLE, desc = "Funding account"), | ||
to_account(WRITABLE, desc = "Recipient account") | ||
)] | ||
Transfer { | ||
/// Test a field comment | ||
lamports: u64, | ||
}, | ||
|
||
/// Provide one required signature and a variable list of other signatures | ||
#[accounts( | ||
required_account(WRITABLE, desc = "Required account"), | ||
signers(SIGNER, multiple, desc = "Signer") | ||
)] | ||
MultipleAccounts, | ||
|
||
/// Consumes a stored nonce, replacing it with a successor | ||
#[accounts( | ||
required_account(SIGNER, WRITABLE, desc = "Required account"), | ||
sysvar(desc = "Sysvar"), | ||
authority(SIGNER, optional, desc = "Authority") | ||
)] | ||
OptionalAccount, | ||
} | ||
|
||
mod test_program { | ||
solana_sdk::declare_id!("8dGutFWpfHymgGDV6is389USqGRqSfpGZyhBrF1VPWDg"); | ||
} | ||
|
||
#[test] | ||
fn test_helper_fns() { | ||
let pubkey0 = Pubkey::new_rand(); | ||
let pubkey1 = Pubkey::new_rand(); | ||
let pubkey2 = Pubkey::new_rand(); | ||
|
||
assert_eq!( | ||
transfer(pubkey0, pubkey1, 42), | ||
Instruction { | ||
program_id: test_program::id(), | ||
accounts: vec![ | ||
AccountMeta { | ||
pubkey: pubkey0, | ||
is_signer: true, | ||
is_writable: true, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey1, | ||
is_signer: false, | ||
is_writable: true, | ||
} | ||
], | ||
data: serialize(&TestInstruction::Transfer { lamports: 42 }).unwrap(), | ||
} | ||
); | ||
|
||
assert_eq!( | ||
multiple_accounts(pubkey0, vec![pubkey1, pubkey2]), | ||
Instruction { | ||
program_id: test_program::id(), | ||
accounts: vec![ | ||
AccountMeta { | ||
pubkey: pubkey0, | ||
is_signer: false, | ||
is_writable: true, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey1, | ||
is_signer: true, | ||
is_writable: false, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey2, | ||
is_signer: true, | ||
is_writable: false, | ||
} | ||
], | ||
data: serialize(&TestInstruction::MultipleAccounts).unwrap(), | ||
} | ||
); | ||
|
||
assert_eq!( | ||
multiple_accounts(pubkey0, vec![]), | ||
Instruction { | ||
program_id: test_program::id(), | ||
accounts: vec![ | ||
AccountMeta { | ||
pubkey: pubkey0, | ||
is_signer: false, | ||
is_writable: true, | ||
} | ||
], | ||
data: serialize(&TestInstruction::MultipleAccounts).unwrap(), | ||
} | ||
); | ||
|
||
assert_eq!( | ||
optional_account(pubkey0, pubkey1, Some(pubkey2)), | ||
Instruction { | ||
program_id: test_program::id(), | ||
accounts: vec![ | ||
AccountMeta { | ||
pubkey: pubkey0, | ||
is_signer: true, | ||
is_writable: true, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey1, | ||
is_signer: false, | ||
is_writable: false, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey2, | ||
is_signer: true, | ||
is_writable: false, | ||
} | ||
], | ||
data: serialize(&TestInstruction::OptionalAccount).unwrap(), | ||
} | ||
); | ||
|
||
assert_eq!( | ||
optional_account(pubkey0, pubkey1, None), | ||
Instruction { | ||
program_id: test_program::id(), | ||
accounts: vec![ | ||
AccountMeta { | ||
pubkey: pubkey0, | ||
is_signer: true, | ||
is_writable: true, | ||
}, | ||
AccountMeta { | ||
pubkey: pubkey1, | ||
is_signer: false, | ||
is_writable: false, | ||
} | ||
], | ||
data: serialize(&TestInstruction::OptionalAccount).unwrap(), | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_from_instruction() { | ||
let transfer = TestInstruction::Transfer { lamports: 42 }; | ||
let verbose_transfer = TestInstructionVerbose::from_instruction(transfer, vec![2, 3]); | ||
assert_eq!( | ||
verbose_transfer, | ||
TestInstructionVerbose::Transfer { | ||
from_account: 2, | ||
to_account: 3, | ||
lamports: 42, | ||
} | ||
); | ||
|
||
let multiple = TestInstruction::MultipleAccounts; | ||
let verbose_multiple = TestInstructionVerbose::from_instruction(multiple, vec![2, 3, 4]); | ||
assert_eq!( | ||
verbose_multiple, | ||
TestInstructionVerbose::MultipleAccounts { | ||
required_account: 2, | ||
signers: vec![3, 4], | ||
} | ||
); | ||
|
||
let optional = TestInstruction::OptionalAccount; | ||
let verbose_optional = TestInstructionVerbose::from_instruction(optional, vec![2, 3, 4]); | ||
assert_eq!( | ||
verbose_optional, | ||
TestInstructionVerbose::OptionalAccount { | ||
required_account: 2, | ||
sysvar: 3, | ||
authority: Some(4), | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
solana_sdk::declare_id!("8dGutFWpfHymgGDV6is389USqGRqSfpGZyhBrF1VPWDg"); |