Skip to content

Commit

Permalink
fix wallet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kabie committed Jun 30, 2024
1 parent 3a610f6 commit 40794e6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ thiserror = "1.0.61"
serde = "1.0.202"
serde_with = "3.8.1"
assert_matches = "1.5.0"
solana-program = "2.0.0"
solana-program = "2.0.1"
solana-program-test = "2.0.1"
solana-sdk = "2.0.1"
solana-client = "2.0.1"
Expand Down
16 changes: 8 additions & 8 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"dephy-ui": "imba serve --esm ./index.html"
},
"dependencies": {
"@metaplex-foundation/umi": "^0.9.1",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.1",
"@metaplex-foundation/umi-signer-wallet-adapters": "^0.9.1",
"@metaplex-foundation/umi-web3js-adapters": "^0.9.1",
"@metaplex-foundation/umi": "^0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
"@metaplex-foundation/umi-signer-wallet-adapters": "^0.9.2",
"@metaplex-foundation/umi-web3js-adapters": "^0.9.2",
"@solana/wallet-adapter-phantom": "^0.9.24",
"@solana/web3.js": "^1.92.1",
"graphql": "^16.8.1",
"graphql-request": "^7.0.1"
"@solana/web3.js": "^1.94.0",
"graphql": "^16.9.0",
"graphql-request": "^7.1.0"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.2",
"imba": "^2.0.0-alpha.235",
"typescript": "^5.4.5"
"typescript": "^5.5.2"
}
}
21 changes: 21 additions & 0 deletions wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# DePHY ID wallet

## Test

```sh
# if `../target/deploy/dephy_id_program.so` not exist, build it in parent first
cd ..
cargo build-sbf

# build wallet program
cd wallet
cargo build-sbf

# if updated `dephy-id-program-client`, regenerate client
bun install
bun generate

# test with local validator
bun clients:js:test
```

2 changes: 1 addition & 1 deletion wallet/clients/js/src/generated/instructions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export async function getCreateInstructionAsync<
if (!accounts.deviceMint.value) {
accounts.deviceMint.value = await findDeviceMintPda({
productMintPubkey: expectAddress(accounts.productMint.value),
devicePubkey: expectAddress(accounts.vendor.value),
devicePubkey: expectAddress(accounts.device.value),
});
}
if (!accounts.payer.value) {
Expand Down
5 changes: 2 additions & 3 deletions wallet/clients/js/test/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ test.before('prepare dephy-id', async () => {

test('it creates a wallet with did token', async (t) => {
const productName = 'Test Wallet Product'
const owner = await generateKeyPairSignerWithSol(client)
const authority = await generateKeyPairSignerWithSol(client)

const {
vendor,
productAssociatedToken,
device,
deviceAssociatedToken
} = await createProductAndDevice(client, owner, productName)
} = await createProductAndDevice(client, authority, productName)

const authority = await generateKeyPairSignerWithSol(client)
const createIx = await getCreateInstructionAsync({
authority,
vendor: vendor.address,
Expand Down
9 changes: 8 additions & 1 deletion wallet/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ fn create<'a>(program_id: &Pubkey, accounts: &'a [AccountInfo<'a>], _bump: u8) -
};
let (product_mint_pubkey, _) = find_product_mint(vendor_pubkey, product_metadata.name, &dephy_id_program_client::ID);
assert_same_pubkeys("product_mint", ctx.accounts.product_mint, &product_mint_pubkey)?;
{
let product_atoken_data = ctx.accounts.product_associated_token.data.borrow();
let product_atoken_state = StateWithExtensions::<Account>::unpack(&product_atoken_data)?;
assert_eq!(product_atoken_state.base.mint, product_mint_pubkey);
assert_eq!(product_atoken_state.base.owner, *device_pubkey);
assert_eq!(product_atoken_state.base.amount, 1);
}

let (device_mint_pubkey, _) = find_device_mint(&product_mint_pubkey, device_pubkey, &dephy_id_program_client::ID);
assert_same_pubkeys("device_mint", ctx.accounts.device_mint, &device_mint_pubkey)?;
Expand All @@ -83,7 +90,7 @@ fn create<'a>(program_id: &Pubkey, accounts: &'a [AccountInfo<'a>], _bump: u8) -
let device_atoken_data = ctx.accounts.device_associated_token.data.borrow();
let device_atoken_state = StateWithExtensions::<Account>::unpack(&device_atoken_data)?;
assert_eq!(device_atoken_state.base.mint, device_mint_pubkey);
assert_eq!(device_atoken_state.base.owner, *device_pubkey);
assert_eq!(device_atoken_state.base.owner, *authority_pubkey);
assert_eq!(device_atoken_state.base.amount, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion wallet/scripts/generate-clients.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ kinobi.update(
deviceMint: {
defaultValue: k.pdaValueNode(k.pdaLinkNode('deviceMint', '@dephy-io/dephy-id-program-client'), [
k.pdaSeedValueNode('productMintPubkey', k.accountValueNode('productMint')),
k.pdaSeedValueNode('devicePubkey', k.accountValueNode('vendor')),
k.pdaSeedValueNode('devicePubkey', k.accountValueNode('device')),
])
},
// #[account(8, name="did_atoken", desc = "DID atoken owned by authority")]
Expand Down

0 comments on commit 40794e6

Please sign in to comment.