Skip to content

Commit

Permalink
Merge pull request #37 from algorandfoundation/refactor/async
Browse files Browse the repository at this point in the history
refactor: remove avm version check as algod latest image is now v4
  • Loading branch information
boblat authored Jan 17, 2025
2 parents 1dd7b2f + d69a6ce commit d610b71
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 70 deletions.
20 changes: 10 additions & 10 deletions tests/arc4/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ const testData = [
Bytes.fromHex(`${'00'.repeat(31)}ff`),
]

describe('arc4.Address', async () => {
describe('arc4.Address', () => {
const ctx = new TestExecutionContext()
afterEach(async () => {
afterEach(() => {
ctx.reset()
})

test.each(testData)('create address from bytes', async (value) => {
test.each(testData)('create address from bytes', (value) => {
const sdkResult = getABIEncodedValue(asUint8Array(value), abiTypeString, {})
const result = new Address(value)
expect(result.bytes).toEqual(sdkResult)
})
test.each(testData)('create address from str', async (value) => {
test.each(testData)('create address from str', (value) => {
const stringValue = encodeAddress(asUint8Array(value))
const sdkResult = getABIEncodedValue(stringValue, abiTypeString, {})
const result = new Address(stringValue)
expect(result.bytes).toEqual(sdkResult)
})
test.each(testData)('create address from Account', async (value) => {
test.each(testData)('create address from Account', (value) => {
const accountValue = Account(value)
const sdkResult = getABIEncodedValue(asUint8Array(accountValue.bytes), abiTypeString, {})
const result = new Address(accountValue)
expect(result.bytes).toEqual(sdkResult)
})

test.each(testData)('get item from address created from bytes', async (value) => {
test.each(testData)('get item from address created from bytes', (value) => {
const uint8ArrayValue = asUint8Array(value)
const result = new Address(value)
let i = 0
Expand All @@ -47,7 +47,7 @@ describe('arc4.Address', async () => {
}
expect(result.length).toEqual(uint8ArrayValue.length)
})
test.each(testData)('get item from address created from str', async (value) => {
test.each(testData)('get item from address created from str', (value) => {
const uint8ArrayValue = asUint8Array(value)
const stringValue = encodeAddress(uint8ArrayValue)
const result = new Address(stringValue)
Expand All @@ -57,7 +57,7 @@ describe('arc4.Address', async () => {
}
expect(result.length).toEqual(uint8ArrayValue.length)
})
test.each(testData)('get item from address created from Account', async (value) => {
test.each(testData)('get item from address created from Account', (value) => {
const uint8ArrayValue = asUint8Array(value)
const accountValue = Account(value)
const result = new Address(accountValue)
Expand All @@ -68,13 +68,13 @@ describe('arc4.Address', async () => {
expect(result.length).toEqual(uint8ArrayValue.length)
})

test.each(testData)('fromBytes method', async (value) => {
test.each(testData)('fromBytes method', (value) => {
const sdkResult = getABIEncodedValue(asUint8Array(value), abiTypeString, {})
const result = interpretAsArc4<Address>(value)
expect(result.bytes).toEqual(sdkResult)
})

test.each(testData)('fromLog method', async (value) => {
test.each(testData)('fromLog method', (value) => {
const sdkResult = getABIEncodedValue(asUint8Array(value), abiTypeString, {})
const paddedValue = Bytes([...asUint8Array(ABI_RETURN_VALUE_LOG_PREFIX), ...asUint8Array(value)])
const result = interpretAsArc4<Address>(paddedValue, 'log')
Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/bool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('arc4.Bool', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/byte.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('arc4.Byte', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
26 changes: 13 additions & 13 deletions tests/arc4/dynamic-array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ const structDynamicArray = {
},
}

describe('arc4.DynamicArray', async () => {
describe('arc4.DynamicArray', () => {
const ctx = new TestExecutionContext()
afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand All @@ -353,7 +353,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('should be able to get bytes representation', async (data) => {
])('should be able to get bytes representation', (data) => {
const sdkResult = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const result = data.array().bytes
expect(result).toEqual(sdkResult)
Expand All @@ -373,7 +373,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('copy dynamic array', async (data) => {
])('copy dynamic array', (data) => {
const sdkResult = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const original = data.array()
const copy = original.copy()
Expand All @@ -396,7 +396,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('get item from dynamic array', async (data) => {
])('get item from dynamic array', (data) => {
const dynamicArray = data.array()
const nativeValues = data.nativeValues()
for (let i = 0; i < dynamicArray.length; i++) {
Expand All @@ -419,7 +419,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('set item in dynamic array', async (data) => {
])('set item in dynamic array', (data) => {
const nativeValues = data.nativeValues()
const nativeValuesCopy = [...nativeValues]
const nativeTemp = nativeValuesCopy.at(-1)!
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('create dynamic array from bytes', async (data) => {
])('create dynamic array from bytes', (data) => {
const sdkEncodedBytes = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const result = data.create(Bytes(sdkEncodedBytes))
const nativeValues = data.nativeValues()
Expand All @@ -474,7 +474,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('push item to dynamic array', async (data) => {
])('push item to dynamic array', (data) => {
const nativeValues = data.nativeValues()
const nativeValuesCopy = [...nativeValues]
nativeValuesCopy.push(nativeValues.at(-1)!)
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('push item to empty dynamic array', async (data) => {
])('push item to empty dynamic array', (data) => {
const nativeValues = data.nativeValues()
const sdkResult = getABIEncodedValue(nativeValues, data.abiTypeString, {})

Expand All @@ -527,7 +527,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('push item to empty dynamic array created from bytes', async (data) => {
])('push item to empty dynamic array created from bytes', (data) => {
const nativeValues = data.nativeValues()
const sdkResult = getABIEncodedValue(nativeValues, data.abiTypeString, {})

Expand All @@ -551,7 +551,7 @@ describe('arc4.DynamicArray', async () => {
stringDynamicArrayOfArrayOfArray,
tupleDynamicArray,
structDynamicArray,
])('pop item from dynamic array', async (data) => {
])('pop item from dynamic array', (data) => {
const nativeValues = data.nativeValues()
const nativeValuesCopy = [...nativeValues]
const nativeValue1 = nativeValuesCopy.pop()
Expand All @@ -570,7 +570,7 @@ describe('arc4.DynamicArray', async () => {
expect(result).toEqual(Bytes(sdkResult))
})

it('set item in nested dynamic array', async () => {
it('set item in nested dynamic array', () => {
const data = stringDynamicArrayOfArrayOfArray
const nativeValues = data.nativeValues()
nativeValues[0][0][0] = 'new value'
Expand All @@ -583,7 +583,7 @@ describe('arc4.DynamicArray', async () => {
expect(result).toEqual(Bytes(sdkResult))
})

it('set item in nested dynamic array created from bytes', async () => {
it('set item in nested dynamic array created from bytes', () => {
const data = stringDynamicArrayOfArrayOfArray
const nativeValues = data.nativeValues()
nativeValues[0][0][0] = 'new value'
Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('arc4.emit', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
22 changes: 11 additions & 11 deletions tests/arc4/static-array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ const structStaticArray = {
},
}

describe('arc4.StaticArray', async () => {
describe('arc4.StaticArray', () => {
const ctx = new TestExecutionContext()
afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand All @@ -340,7 +340,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('should be able to get bytes representation', async (data) => {
])('should be able to get bytes representation', (data) => {
const sdkResult = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const result = data.array().bytes
expect(result).toEqual(Bytes(sdkResult))
Expand All @@ -360,7 +360,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('copy static array', async (data) => {
])('copy static array', (data) => {
const sdkResult = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const original = data.array()
const copy = original.copy()
Expand All @@ -383,7 +383,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('get item from static array', async (data) => {
])('get item from static array', (data) => {
const staticArray = data.array()
const nativeValues = data.nativeValues()
for (let i = 0; i < staticArray.length; i++) {
Expand All @@ -406,7 +406,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('set item in static array', async (data) => {
])('set item in static array', (data) => {
const nativeValues = data.nativeValues()
const nativeValuesCopy = [...nativeValues]
const nativeTemp = nativeValuesCopy.at(-1)!
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('create static array from bytes', async (data) => {
])('create static array from bytes', (data) => {
const sdkEncodedBytes = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const result = data.create(Bytes(sdkEncodedBytes))
const nativeValues = data.nativeValues()
Expand All @@ -461,7 +461,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('get item from static array created from bytes', async (data) => {
])('get item from static array created from bytes', (data) => {
const nativeValues = data.nativeValues()
const sdkEncodedBytes = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const staticArray = data.create(Bytes(sdkEncodedBytes))
Expand All @@ -485,7 +485,7 @@ describe('arc4.StaticArray', async () => {
stringStaticArrayOfArrayOfArray,
tupleStaticArray,
structStaticArray,
])('set item in static array created from bytes', async (data) => {
])('set item in static array created from bytes', (data) => {
const nativeValues = data.nativeValues()
const nativeValuesCopy = [...nativeValues]
const nativeTemp = nativeValuesCopy.at(-1)!
Expand All @@ -504,7 +504,7 @@ describe('arc4.StaticArray', async () => {
expect(result).toEqual(Bytes(sdkResult))
})

it('set item in nested static array', async () => {
it('set item in nested static array', () => {
const data = stringStaticArrayOfArrayOfArray
const nativeValues = data.nativeValues()
nativeValues[0][0][0] = 'new value'
Expand All @@ -517,7 +517,7 @@ describe('arc4.StaticArray', async () => {
expect(result).toEqual(Bytes(sdkResult))
})

it('set item in nested static array create from bytes', async () => {
it('set item in nested static array create from bytes', () => {
const data = stringStaticArrayOfArrayOfArray
const nativeValues = data.nativeValues()
nativeValues[0][0][0] = 'new value'
Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/str.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('arc4.Str', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
12 changes: 6 additions & 6 deletions tests/arc4/tuple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ const testDataWithArray = [
},
]

describe('arc4.Tuple', async () => {
describe('arc4.Tuple', () => {
const ctx = new TestExecutionContext()
afterEach(async () => {
afterEach(() => {
ctx.reset()
})

test.each(testData)('should be able to get bytes representation', async (data) => {
test.each(testData)('should be able to get bytes representation', (data) => {
const sdkResult = getABIEncodedValue(data.nativeValues(), data.abiTypeString, {})
const result = data.tuple().bytes
expect(result).toEqual(Bytes(sdkResult))
})

test.each(testData)('should be able to get native representation', async (data) => {
test.each(testData)('should be able to get native representation', (data) => {
const nativeValues = data.nativeValues()
const result = data.tuple().native
for (let i = 0; i < nativeValues.length; i++) {
Expand All @@ -312,7 +312,7 @@ describe('arc4.Tuple', async () => {
expect(result.length).toEqual(nativeValues.length)
})

test.each(testData)('create tuple from bytes', async (data) => {
test.each(testData)('create tuple from bytes', (data) => {
const nativeValues = data.nativeValues()
const sdkEncodedBytes = getABIEncodedValue(nativeValues, data.abiTypeString, {})

Expand All @@ -324,7 +324,7 @@ describe('arc4.Tuple', async () => {
}
})

test.each(testDataWithArray)('update array values in tuple', async (data) => {
test.each(testDataWithArray)('update array values in tuple', (data) => {
const sdkResult = getABIEncodedValue(data.updatedNativeValues(), data.abiTypeString, {})
const tuple = data.tuple()
data.update(tuple as DeliberateAny)
Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/ufixednxm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('arc4.UFixedNxM', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
2 changes: 1 addition & 1 deletion tests/arc4/uintn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('arc4.UintN', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
8 changes: 0 additions & 8 deletions tests/avm-invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ const algorandClient = Lazy(() => {

export const INITIAL_BALANCE_MICRO_ALGOS = Number(20e6)

export const getAlgorandAppClientV11 = async (appSpec: AppSpec) => {
if ((await getAlgodMajorVersion()) < 4) {
return undefined
}
const [appClient, _] = await getAlgorandAppClientWithApp(appSpec)
return appClient
}

export const getAlgorandAppClient = async (appSpec: AppSpec) => {
const [appClient, _] = await getAlgorandAppClientWithApp(appSpec)
return appClient
Expand Down
2 changes: 1 addition & 1 deletion tests/crypto-op-codes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('crypto op codes', async () => {
const [appClient, app] = await getAlgorandAppClientWithApp(appSpecJson as AppSpec)
const ctx = new TestExecutionContext()

afterEach(async () => {
afterEach(() => {
ctx.reset()
})

Expand Down
Loading

0 comments on commit d610b71

Please sign in to comment.