Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing failed in solana playground (Instruction index: 0; Reason: Program failed to complete.) #98

Open
mondalraj opened this issue Mar 28, 2023 · 1 comment

Comments

@mondalraj
Copy link

I am writing a smart contract with seahorse.
However it successfully build and deployed, but when I run the addProduct() test, it fails
It is giving me the error-

Testing 'addProduct'...
❌  Test 'addProduct' failed: 
Instruction index: 0
Reason: Program failed to complete.

Here is my smart contract -

# Built with Seahorse v0.2.4

from seahorse.prelude import *

declare_id('A81QxcQJrfZprjbNkvC9a9gSi2huQu45bSDsECTX2aJE')

class UserProfile(Account):
  owner: Pubkey
  name: str
  email_address: str
  phone: str
  address: str
  role: str #Supplier or Buyer
  no_of_products: u64

class Product(Account):
  # Relation with Supplier
  owner: Pubkey
  product_id: u64
  name: str
  description: str
  price: f64
  quantity: u64
  image_url: str

class Transaction(Account):
  product_id: u64
  product_owner: Pubkey
  buyer: Pubkey
  amount: f64
  created_at: str
  transaction_type: str #Ordered or Delivered
  

@instruction
def create_user(
  owner: Signer, 
  user: Empty[UserProfile],
  name: str,
  email_address: str,
  phone: str,
  address: str,
  role: str,
):
  user_profile = user.init(
    payer = owner,
    seeds = ['user', owner],
  )
  user_profile.owner = owner.key()
  user_profile.name = name
  user_profile.email_address = email_address
  user_profile.phone = phone
  user_profile.address = address
  user_profile.role = role
  user_profile.no_of_products = 0
  

@instruction
def add_product(
  owner: Signer,
  product: Empty[Product],
  user: UserProfile,
  product_id: u64,
  name: str,
  description: str,
  price: f64,
  quantity: u64,
  image_url: str,
):
  assert user.owner == owner.key(), 'Incorrect Owner'
  assert product_id == user.no_of_products + 1, 'Incorrect Product ID'

  product_account = product.init(
    payer = owner,
    seeds = ['product', owner, product_id],
    # space = 8 + space
  )
  product_account.owner = owner.key()
  product_account.product_id = product_id
  product_account.name = name
  product_account.description = description
  product_account.price = price
  product_account.quantity = quantity
  product_account.image_url = image_url
  
  user.no_of_products += 1

  new_product_event = NewProductEvent(product_account.owner, product_account.product_id)
  new_product_event.emit()

### Events ###

class NewProductEvent(Event):
  owner: Pubkey
  product_id: u64

  def __init__(self, owner: Pubkey, product_id: u64):
    self.owner = owner
    self.product_id = product_id

Could you please help me out with the error.
I am new to the Solana + Seahorse Ecosystem.

Thank You

@acheroncrypto
Copy link
Contributor

Hey, it's hard to debug without seeing your input and the full program logs.

You can get the full logs if you disable "Preflight checks" and enable "Show transaction details" in Solana Playground settings(bottom-left gear icon) before you send the test transaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants