Skip to content

Commit

Permalink
Merge pull request #2802 from onflow/supun/stable-cadence
Browse files Browse the repository at this point in the history
Fix Test framework's TestAccount's type name
  • Loading branch information
SupunS authored Sep 21, 2023
2 parents a88e5eb + 091e17f commit e857884
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion npm-packages/cadence-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onflow/cadence-parser",
"version": "0.41.1",
"version": "1.0.0-preview.1",
"description": "The Cadence parser",
"homepage": "https://github.com/onflow/cadence",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion runtime/stdlib/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const testTransactionResultTypeName = "TransactionResult"
const testResultStatusTypeName = "ResultStatus"
const testResultStatusTypeSucceededCaseName = "succeeded"
const testResultStatusTypeFailedCaseName = "failed"
const testAccountTypeName = "Account"
const testAccountTypeName = "TestAccount"
const testErrorTypeName = "Error"
const testMatcherTypeName = "Matcher"

Expand Down
46 changes: 46 additions & 0 deletions runtime/stdlib/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,51 @@ func TestBlockchain(t *testing.T) {
// TODO: Add more tests for the remaining functions.
}

func TestBlockchainAccount(t *testing.T) {

t.Parallel()

t.Run("create account", func(t *testing.T) {
t.Parallel()

const script = `
import Test
access(all) fun test() {
let blockchain = Test.newEmulatorBlockchain()
let account = blockchain.createAccount()
assert(account.address == 0x0100000000000000)
}
`

testFramework := &mockedTestFramework{
newEmulatorBackend: func() Blockchain {
return &mockedBlockchain{
createAccount: func() (*Account, error) {
return &Account{
PublicKey: &PublicKey{
PublicKey: []byte{1, 2, 3},
SignAlgo: sema.SignatureAlgorithmECDSA_P256,
},
Address: common.Address{1},
}, nil
},

stdlibHandler: func() StandardLibraryHandler {
return nil
},
}
},
}

inter, err := newTestContractInterpreterWithTestFramework(t, script, testFramework)
require.NoError(t, err)

_, err = inter.Invoke("test")
require.NoError(t, err)
})
}

type mockedTestFramework struct {
newEmulatorBackend func() Blockchain
readFile func(s string) (string, error)
Expand All @@ -2555,6 +2600,7 @@ func (m mockedTestFramework) ReadFile(fileName string) (string, error) {
return m.readFile(fileName)
}

// mockedBlockchain is the implementation of `Blockchain` for testing purposes.
type mockedBlockchain struct {
runScript func(inter *interpreter.Interpreter, code string, arguments []interpreter.Value)
createAccount func() (*Account, error)
Expand Down
2 changes: 1 addition & 1 deletion version.go

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

0 comments on commit e857884

Please sign in to comment.